#~~~  Italy's Democratic Quality and the Role of Political Parties  ~~~
#~~~  Comparative Empirical Patterns  ~~~

#~~~  Guido Panzano & Sofia Marini  ~~~

#~~~  Rivista Italiana di Scienza Politica  ~~~
#~~~  Italian Political Science Review  ~~~

#==== Necessary packages =====
library(readxl)
library(tidyverse)
library(ggplot2)
library(ggpubr)
library(gghighlight)
library(vtable)
library(plm)
library(fixest)
library(modelsummary)

# Set your WD where you save the folder with the data files and the script
# setwd("XXX")

##==== Descriptives =====
data_descriptives <- read_xlsx("data_descriptives.xlsx")
labs <- c("RULEOFLAW" = 	"Rule of Law (DB)",
          "v2x_rule" = 	"Rule of Law (V-Dem)",
          "wbgi_rle" = 	"Rule of Law (WB)",
          "`Rule of Law`" = "Rule of Law (BTI)",
          "wjp_overall" = "Rule of Law (WJP)",
          "fh_rol" = "Rule of Law (FH)",
          "TRANSPAR" = "Transparency (DB)",
          "RL_QUAL3" = "Confidence in the policy (DB)",
          "v2x_accountability" = 	"Accountability (V-Dem)",
          "wbgi_vae" = 	"Accountability (WB)",
          "MUTUCONS" = 	"Mutual constraints of executive power (DB)",
          "`Executive Accountability`" = "Executive accountability (BTI)",
          "`Independent Supervisory Bodies`" = 
            "Independent Supervisory Bodies (BTI)",
          "electoral_reforms" = "Electoral reforms (IDEA)",
          "v2x_diagacc" = "Diagonal accountability (V-Dem)",
          "PAR_EFPA" = 	"Effective participation (DB)",
          "v2x_partip" = 	"Participation (V-Dem)",
          "fh_ppp" = 	"Political pluralism and participation (FH)",
          "v2cagenmob" = "Mass mobilization (V-Dem)",
          "van_part" = "Participation index (Vanhanen)",
          "turnout" = "Turnout (IDEA)",
          "ideavt_euvt" = "Turnout EP elections (VDT)",
          "closure_c" = 	"Party system closure (PSGO)",
          "psi_psi1" = 	"Party system innovation (DEV)",
          "volatility" = 	"Volatility (DEV)",
          "COMPET" = "Competition (DB)",
          "van_comp" = "Competition index (Vanhanen)",
          "enep" = "Electoral Fragmentation (PSGO)",
          "cpds_frleg" = "Legislative fract. party system (Rae/CPD)",
          "evep_tv" = "Total volatility EP (DEV)",
          "v2clslavef" = 	"Freedom from forced labor for women (V-Dem)",
          "v2clkill" = 	"Freedom from political killings (V-Dem)",
          "v2clacfree" = 	"Freedom of academic discussion (V-Dem)",
          "v2cltort" = 	"Freedom from torture (V-Dem)",
          "v2clstown" = 	"State ownership of economy (V-Dem)",
          "fhp_score5" = 	"Freedom of the Press (FoP)",
          "fh_feb" = 	"Freedom of expression and belief (FH)",
          "`Civil Rights and Political Liberties`" = 	
            "Civil Rights and Political liberties (BTI)",
          "e_peaveduc" = 	"Education 15+ (CLIO)",
          "income_gini" = 	"Income gini (LIS)",
          "v2elsnlsff" = 	"Subnational election eveness (V-Dem)",
          "v2pehealth" = "Health inequality (V-Dem)",
          "gii_gii" = "Gender inequality index (UN)",
          "oecd_incinequal_t1a" = "Income gini (CSP)",
          "`Social Inclusion`" = "Social inclusion (BTI)",
          "`Health`" = "Health (BTI)",
          "Issuecongr" = 	"Left-right issue congruence (DB)",
          "hum_satdem" = 	"Satisfaction with democracy (HUMAN)",
          "Confgov" = "Confidence in government (DB)",
          "fulfil2" = "Party pledge fulfillment (CPP)",
          "v2paind_w" = "Party personalization",
          "pi_z" = "Party institutionalization")

# Table A3
sumtable(data_descriptives,
         vars= c("RULEOFLAW", "v2x_rule", "wbgi_rle", 
                 "Rule of Law", "wjp_overall", "fh_rol", "TRANSPAR", "RL_QUAL3",
                 "v2x_accountability", "wbgi_vae", "MUTUCONS",
                 "Executive Accountability", "Independent Supervisory Bodies",
                 "electoral_reforms", "v2x_diagacc",
                 "PAR_EFPA", "v2x_partip", "fh_ppp", 
                 "v2cagenmob", "van_part", "turnout", "ideavt_euvt",
                 "closure_c", "psi_psi1", "volatility", 
                 "COMPET", "van_comp", "enep", "cpds_frleg", "evep_tv",
                 "v2clslavef", "v2clkill", "v2clacfree", 
                 "v2cltort", "v2clstown", "fhp_score5", "fh_feb", 
                 "Civil Rights and Political Liberties",
                 "e_peaveduc", "income_gini", "v2elsnlsff", 
                 "v2pehealth", "gii_gii", "oecd_incinequal_t1a", "Social Inclusion",
                 "Health", "Confgov", "Issuecongr", "hum_satdem", "fulfil2", 
                 "v2paind_w", "pi_z"),
         # out = "browser",
         # file = "summary_statistics",
         summ=c('notNA(x)', 'min(x)', 'max(x)', 'mean(x)', 'sd(x)', 
                'pctile(x)[25]', 'pctile(x)[75]'),
         summ.names=c('N (not NA)', 'Min',  'Max', 'Mean', 'SD', 
                      '2nd Percentile', '3rd Percentile'),
         add.median=FALSE,
         group.long=FALSE,
         group.test=FALSE,
         group.weights =NA,
         col.breaks=NA,
         factor.percent=TRUE,
         logical.labels=c('No','Yes'),
         labels=labs,
         title='Summary Statistics',
         note = NA, 
         anchor=NA,
         col.width=NA,
         col.align=NA,
         align=NA,
         note.align='l',
         fit.page=NA,
         simple.kable=FALSE,
         obs.function=NA,
         opts=list())

##==== Data modification for graphs =====
data_graphs <- read_xlsx("data_graphs.xlsx")

# Re-scale variables between 0 and 1
DB_vdem_lib_dem <- data_graphs %>%
  mutate(
    RULEOFLAW = RULEOFLAW/5,
    TRANSPAR = TRANSPAR/5,
    RL_QUAL3 = RL_QUAL3/6,
    `Rule of Law` = `Rule of Law`/10,
    wbgi_rle = wbgi_rle/2.3,
    fh_rol = fh_rol/18,
    wbgi_vae = wbgi_vae/2,
    v2x_accountability = v2x_accountability/2.3,
    v2x_diagacc = v2x_diagacc/2.3,
    MUTUCONS = MUTUCONS/5,
    wbgi_vae = wbgi_vae/2,
    `Executive Accountability` = `Executive Accountability`/10,
    `Legislative Actors' Resources` = `Legislative Actors' Resources`/10,
    `Independent Supervisory Bodies` = `Independent Supervisory Bodies`/10,
    v2cagenmob = (v2cagenmob+2.6720)/6.5,
    PAR_EFPA = PAR_EFPA/5,
    turnout = turnout/100,
    van_part = van_part/100,
    ideavt_euvt = ideavt_euvt/100,
    fh_ppp = fh_ppp/18,
    COMPET = COMPET/5,
    closure_c = closure_c/100,
    enep = enep/11,
    volatility = volatility/40,
    van_comp = van_comp/100,
    evep_tv = evep_tv/55,
    psi_psi1 = psi_psi1/37,
    v2cltort = v2cltort/4,
    v2clkill = v2clkill/5,
    v2clslavef = v2clslavef/4,
    v2clacfree = v2clacfree/5,
    v2clstown = v2clstown/4,
    v2cltort = v2cltort/4,
    fhp_score5 = fhp_score5/55,
    fh_feb = fh_feb/18,
    `Civil Rights and Political Liberties` = `Civil Rights and Political Liberties`/10,
    e_peaveduc = e_peaveduc/15,
    v2pehealth = v2pehealth/4,
    v2elsnlsff = v2elsnlsff/4,
    `Social Inclusion` = `Social Inclusion`/10,
    `Health` = `Health`/10,
    Confgov = Confgov/7,
    Issuecongr = Issuecongr/8,
    hum_satdem = hum_satdem/100)

# Compute country average for plot, global and European level, and fill missings
DB_vdem_lib_dem_average <- DB_vdem_lib_dem %>% group_by(year) %>%
  summarise(
    across(everything(), mean, na.rm = T),
    .groups = 'drop')
DB_vdem_lib_dem_average$country_name <- "average_lib_dem"

DB_vdem_lib_dem_EU <- DB_vdem_lib_dem %>%
  filter(country_name %in% c("Austria", "Belgium", "Cyprus", "Czechia", "Denmark",
                             "Estonia", "Finland", "France", "Germany", "Greece", 
                             "Hungary", "Ireland", "Italy", "Latvia", "Lithuania",
                             "Luxembourg", "Netherlands", "Poland", "Portugal", 
                             "Slovakia", "Slovenia", "Spain", "Sweden"))

DB_vdem_lib_dem_EU_average <- DB_vdem_lib_dem_EU %>% group_by(year) %>%
  summarise(
    across(everything(), mean, na.rm = T),
    .groups = 'drop')
DB_vdem_lib_dem_EU_average$country_name <- "average_lib_dem"

DB_vdem_lib_dem <- DB_vdem_lib_dem %>% 
  mutate(across(v2x_polyarchy:`Ombuds Office`, as.numeric))
DB_vdem_lib_dem_average <- DB_vdem_lib_dem_average %>% 
  mutate(across(v2x_polyarchy:`Ombuds Office`, as.numeric))
DB_vdem_lib_dem <- bind_rows(DB_vdem_lib_dem, DB_vdem_lib_dem_average)

DB_vdem_lib_dem_subgroup <- DB_vdem_lib_dem %>%
  filter(country_name%in%c("Italy","average_lib_dem")) %>%
  fill(income_gini)
DB_vdem_lib_dem_subgroup <- DB_vdem_lib_dem_subgroup %>% 
  mutate(across(v2x_polyarchy:`Ombuds Office`, as.numeric))

DB_vdem_lib_dem_EU <- DB_vdem_lib_dem_EU %>% 
  mutate(across(v2x_polyarchy:`Ombuds Office`, as.numeric))
DB_vdem_lib_dem_EU_average <- DB_vdem_lib_dem_EU_average %>% 
  mutate(across(v2x_polyarchy:`Ombuds Office`, as.numeric))
DB_vdem_lib_dem_EU <- bind_rows(DB_vdem_lib_dem_EU, DB_vdem_lib_dem_EU_average)

DB_vdem_lib_dem_EU_subgroup <- DB_vdem_lib_dem_EU %>%
  filter(country_name%in%c("Italy","average_lib_dem")) %>%
  fill(income_gini)
DB_vdem_lib_dem_EU_subgroup <- DB_vdem_lib_dem_EU_subgroup %>% 
  mutate(across(v2x_polyarchy:`Ombuds Office`, as.numeric))

#==== Graphs =====
### ==== 1. Rule of law =====
# V-Dem
dim1_vdem_rol <- ggplot() +
  geom_boxplot(aes(year, v2x_rule, group = year), 
               data = DB_vdem_lib_dem, 
               outlier.color="grey",
               color="grey",
               varwidth = TRUE) +
  geom_line(aes(year, v2x_rule, group = country_name, linetype = country_name), 
            data = DB_vdem_lib_dem_subgroup) +  
  scale_linetype_manual(values=c("dotdash", "solid")) +
  scale_x_continuous(breaks=c(1995, 2000, 2005, 2010, 2015, 2020),
                     name = NULL) +
  scale_y_continuous(name="Rule of Law (V-Dem)") +
  theme(legend.position="bottom",legend.text=element_text(size=7),
        legend.title = element_blank())  +
  theme_bw() + theme(panel.border = element_blank(),
                     axis.line = element_line(colour = "grey"))

# DB
dim1_db_rol <- ggplot() +
  geom_boxplot(aes(year, RULEOFLAW, group = year), 
               data = DB_vdem_lib_dem, 
               outlier.color="grey",
               color="grey",
               varwidth = TRUE) +
  geom_line(aes(year, RULEOFLAW, group = country_name, linetype = country_name), 
            data = DB_vdem_lib_dem_subgroup) +  
  scale_linetype_manual(values=c("dotdash", "solid")) +
  scale_x_continuous(breaks=c(1995,2000, 2005, 2010, 2015),
                     limits=c(1993.5, 2017.5),
                     name = NULL) +
  scale_y_continuous(name="Rule of Law (DB)") +
  theme(legend.position="bottom",legend.text=element_text(size=7),
        legend.title = element_blank())  +
  theme_bw() + theme(panel.border = element_blank(),
                     axis.line = element_line(colour = "grey"))

# WB
dim1_wb_rol <- ggplot() +
  geom_boxplot(aes(year, wbgi_rle, group = year), 
               data = DB_vdem_lib_dem, 
               outlier.color="grey",
               color="grey",
               varwidth = TRUE) +
  geom_line(aes(year, wbgi_rle, group = country_name, linetype = country_name), 
            data = DB_vdem_lib_dem_subgroup) +  
  scale_linetype_manual(values=c("dotdash", "solid")) +
  scale_x_continuous(breaks=c(2000, 2005, 2010, 2015, 2020),
                     limits=c(1995.5, 2022.5),
                     name = NULL) +
  scale_y_continuous(name="Rule of Law (WB)") +
  theme(legend.position="bottom",legend.text=element_text(size=7),
        legend.title = element_blank())  +
  theme_bw() + theme(panel.border = element_blank(),
                     axis.line = element_line(colour = "grey"))

# Main text
Figure_1 <- ggarrange(ggarrange(dim1_vdem_rol, dim1_db_rol, dim1_wb_rol, 
                                ncol = 3, legend = "none"), nrow = 1)

# V-Dem
dim1_vdem_rol_eu <- ggplot() +
  geom_boxplot(aes(year, v2x_rule, group = year), 
               data = DB_vdem_lib_dem_EU, 
               outlier.color="grey",
               color="grey",
               varwidth = TRUE) +
  geom_line(aes(year, v2x_rule, group = country_name, linetype = country_name), 
            data = DB_vdem_lib_dem_EU_subgroup) +  
  scale_linetype_manual(values=c("dotdash", "solid")) +
  scale_x_continuous(breaks=c(1995,2000, 2005, 2010, 2015, 2020),
                     name = NULL) +
  scale_y_continuous(name="Rule of Law (V-Dem)") +
  theme(legend.position="bottom",legend.text=element_text(size=7),
        legend.title = element_blank())  +
  theme_bw() + theme(panel.border = element_blank(),
                     axis.line = element_line(colour = "grey"))

# DB
dim1_db_rol_eu <- ggplot() +
  geom_boxplot(aes(year, RULEOFLAW, group = year), 
               data = DB_vdem_lib_dem_EU, 
               outlier.color="grey",
               color="grey",
               varwidth = TRUE) +
  geom_line(aes(year, RULEOFLAW, group = country_name, linetype = country_name), 
            data = DB_vdem_lib_dem_EU_subgroup) +  
  scale_linetype_manual(values=c("dotdash", "solid")) +
  scale_x_continuous(breaks=c(1995,2000, 2005, 2010, 2015),
                     limits=c(1993.5, 2017.5),
                     name = NULL) +
  scale_y_continuous(name="Rule of Law (DB)") +
  theme(legend.position="bottom",legend.text=element_text(size=7),
        legend.title = element_blank())  +
  theme_bw() + theme(panel.border = element_blank(),
                     axis.line = element_line(colour = "grey"))

# WB
dim1_wb_rol_eu <- ggplot() +
  geom_boxplot(aes(year, wbgi_rle, group = year), 
               data = DB_vdem_lib_dem_EU, 
               outlier.color="grey",
               color="grey",
               varwidth = TRUE) +
  geom_line(aes(year, wbgi_rle, group = country_name, linetype = country_name), 
            data = DB_vdem_lib_dem_EU_subgroup) +  
  scale_linetype_manual(values=c("dotdash", "solid")) +
  scale_x_continuous(breaks=c(1995,2000, 2005, 2010, 2015, 2020),
                     name = NULL) +
  scale_y_continuous(name="Rule of Law (WB)") +
  theme(legend.position="bottom",legend.text=element_text(size=7),
        legend.title = element_blank())  +
  theme_bw() + theme(panel.border = element_blank(),
                     axis.line = element_line(colour = "grey"))

# Appendix (EU countries)
Figure_A10 <- ggarrange(ggarrange(dim1_vdem_rol_eu, dim1_db_rol_eu, dim1_wb_rol_eu, ncol = 3, nrow = 1,
                                  legend = "none"))

# BTI
dim1_bti_rol <- ggplot() +
  geom_boxplot(aes(year, `Rule of Law`, group = year), 
               data = DB_vdem_lib_dem, 
               outlier.color="grey",
               color="grey",
               varwidth = TRUE) +
  geom_line(aes(year, `Rule of Law`, group = country_name, linetype = country_name), 
            data = DB_vdem_lib_dem_subgroup) +  
  scale_linetype_manual(values=c("dotdash", "solid")) +
  scale_x_continuous(breaks=c(2015, 2020),
                     limits=c(2014.5, 2022.5),
                     name = NULL) +
  scale_y_continuous(name="Rule of Law (BTI)") +
  theme(legend.position="bottom",legend.text=element_text(size=7),
        legend.title = element_blank())  +
  theme_bw() + theme(panel.border = element_blank(),
                     axis.line = element_line(colour = "grey"))

# WJP
dim1_wjp_rol <- ggplot() +
  geom_boxplot(aes(year, wjp_overall, group = year), 
               data = DB_vdem_lib_dem, 
               outlier.color="grey",
               color="grey",
               varwidth = TRUE) +
  geom_line(aes(year, wjp_overall, group = country_name, linetype = country_name), 
            data = DB_vdem_lib_dem_subgroup) +  
  scale_linetype_manual(values=c("dotdash", "solid")) +
  scale_x_continuous(breaks=c(2015, 2020),
                     limits=c(2011.5, 2023),
                     name = NULL) +
  scale_y_continuous(name="Rule of Law (WJP)") +
  theme(legend.position="bottom",legend.text=element_text(size=7),
        legend.title = element_blank())  +
  theme_bw() + theme(panel.border = element_blank(),
                     axis.line = element_line(colour = "grey"))

# FH
dim1_fh_rol <- ggplot() +
  geom_boxplot(aes(year, fh_rol, group = year), 
               data = DB_vdem_lib_dem, 
               outlier.color="grey",
               color="grey",
               varwidth = TRUE) +
  geom_line(aes(year, fh_rol, group = country_name, linetype = country_name), 
            data = DB_vdem_lib_dem_subgroup) +  
  scale_linetype_manual(values=c("dotdash", "solid")) +
  scale_x_continuous(breaks=c(1995, 2000, 2005, 2010, 2015, 2020),
                     limits=c(2004.5, 2021.5),
                     name = NULL) +
  scale_y_continuous(name="Rule of Law (FH)") +
  theme(legend.position="bottom",legend.text=element_text(size=7),
        legend.title = element_blank())  +
  theme_bw() + theme(panel.border = element_blank(),
                     axis.line = element_line(colour = "grey"))

# DB
dim1_db_tra <- ggplot() +
  geom_boxplot(aes(year, TRANSPAR, group = year), 
               data = DB_vdem_lib_dem, 
               outlier.color="grey",
               color="grey",
               varwidth = TRUE) +
  geom_line(aes(year, TRANSPAR, group = country_name, linetype = country_name), 
            data = DB_vdem_lib_dem_subgroup) +  
  scale_linetype_manual(values=c("dotdash", "solid")) +
  scale_x_continuous(breaks=c(1995,2000, 2005, 2010, 2015),
                     limits=c(1993.5, 2017.5),
                     name = NULL) +
  scale_y_continuous(name="Transparency (DB)") +
  theme(legend.position="bottom",legend.text=element_text(size=7),
        legend.title = element_blank())  +
  theme_bw() + theme(panel.border = element_blank(),
                     axis.line = element_line(colour = "grey"))

# DB
dim1_db_pol <- ggplot() +
  geom_boxplot(aes(year, RL_QUAL3, group = year), 
               data = DB_vdem_lib_dem, 
               outlier.color="grey",
               color="grey",
               varwidth = TRUE) +
  geom_line(aes(year, RL_QUAL3, group = country_name, linetype = country_name), 
            data = DB_vdem_lib_dem_subgroup) +  
  scale_linetype_manual(values=c("dotdash", "solid")) +
  scale_x_continuous(breaks=c(1995,2000, 2005, 2010, 2015),
                     limits=c(1993.5, 2017.5),
                     name = NULL) +
  scale_y_continuous(name="Confidence in the police (DB)") +
  theme(legend.position="bottom",legend.text=element_text(size=7),
        legend.title = element_blank())  +
  theme_bw() + theme(panel.border = element_blank(),
                     axis.line = element_line(colour = "grey"))

# Appendix (alternative indicators)
Figure_A11 <- ggarrange(ggarrange(dim1_bti_rol, dim1_wjp_rol, dim1_fh_rol, 
                                  dim1_db_tra, dim1_db_pol, ncol = 3,
                                  nrow = 2, legend = "none"))

# All plots
Figure_1
Figure_A10
Figure_A11

###==== 2. Accountability =====
# V-Dem
dim2_vdem_acc <- ggplot() +
  geom_boxplot(aes(year, v2x_accountability, group = year), 
               data = DB_vdem_lib_dem, 
               outlier.color="grey",
               color="grey",
               varwidth = TRUE) +
  geom_line(aes(year, v2x_accountability, group = country_name, linetype = country_name), 
            data = DB_vdem_lib_dem_subgroup) +  
  scale_x_continuous(breaks=c(1995,2000, 2005, 2010, 2015, 2020),
                     name = NULL) +
  scale_y_continuous(name="Accountability (V-Dem)") +
  scale_linetype_manual(values=c("dotdash", "solid")) +
  theme(legend.position="bottom",legend.text=element_text(size=7),
        legend.title = element_blank())  +
  theme_bw() + theme(panel.border = element_blank(),
                     axis.line = element_line(colour = "grey"))

# DB
dim2_db_acc <- ggplot() +
  geom_boxplot(aes(year, MUTUCONS, group = year), 
               data = DB_vdem_lib_dem, 
               outlier.color="grey",
               color="grey",
               varwidth = TRUE) +
  geom_line(aes(year, MUTUCONS, group = country_name, linetype = country_name), 
            data = DB_vdem_lib_dem_subgroup) +  
  scale_x_continuous(breaks=c(1995,2000, 2005, 2010, 2015),
                     limits=c(1993.5, 2018),
                     name = NULL) +
  scale_y_continuous(name="Mutual Constraints of Institutional Power (DB)") +
  scale_linetype_manual(values=c("dotdash", "solid")) +
  theme(legend.position="bottom",legend.text=element_text(size=7),
        legend.title = element_blank())  +
  theme_bw() + theme(panel.border = element_blank(),
                     axis.line = element_line(colour = "grey"))

# WB
dim2_wb_acc <- ggplot() +
  geom_boxplot(aes(year, wbgi_vae, group = year),
               data = DB_vdem_lib_dem,
               outlier.color="grey",
               color="grey",
               varwidth = TRUE) +
  geom_line(aes(year, wbgi_vae, group = country_name, linetype = country_name), 
            data = DB_vdem_lib_dem_subgroup) +  
  scale_x_continuous(breaks=c(1995, 2000, 2005, 2010, 2015, 2020),
                     limits = c(1995,2022.5),
                     name = NULL) +
  scale_y_continuous(name="Accountability (WB)") +
  scale_linetype_manual(values=c("dotdash", "solid")) +
  theme(legend.position="bottom",legend.text=element_text(size=7),
        legend.title = element_blank())  +
  theme_bw() + theme(panel.border = element_blank(),
                     axis.line = element_line(colour = "grey"))

# Main text
Figure_2 <- ggarrange(ggarrange(dim2_vdem_acc, dim2_db_acc, dim2_wb_acc, ncol = 3, nrow = 1, legend = "none"))

# V-Dem
dim2_vdem_acc_eu <- ggplot() +
  geom_boxplot(aes(year, v2x_accountability, group = year), 
               data = DB_vdem_lib_dem_EU, 
               outlier.color="grey",
               color="grey",
               varwidth = TRUE) +
  geom_line(aes(year, v2x_accountability, group = country_name, linetype = country_name), 
            data = DB_vdem_lib_dem_EU_subgroup) +  
  scale_x_continuous(breaks=c(1995,2000, 2005, 2010, 2015, 2020),
                     name = NULL) +
  scale_y_continuous(name="Accountability (V-Dem)") +
  scale_linetype_manual(values=c("dotdash", "solid")) +
  theme(legend.position="bottom",legend.text=element_text(size=7),
        legend.title = element_blank())  +
  theme_bw() + theme(panel.border = element_blank(),
                     axis.line = element_line(colour = "grey"))

# DB
dim2_db_acc_eu <- ggplot() +
  geom_boxplot(aes(year, MUTUCONS, group = year), 
               data = DB_vdem_lib_dem_EU, 
               outlier.color="grey",
               color="grey",
               varwidth = TRUE) +
  geom_line(aes(year, MUTUCONS, group = country_name, linetype = country_name), 
            data = DB_vdem_lib_dem_EU_subgroup) +  
  scale_x_continuous(breaks=c(1995,2000, 2005, 2010, 2015),
                     limits=c(1993.5, 2018),
                     name = NULL) +
  scale_y_continuous(name="Mutual Constraints of Institutional Power (DB)") +
  scale_linetype_manual(values=c("dotdash", "solid")) +
  theme(legend.position="bottom",legend.text=element_text(size=7),
        legend.title = element_blank())  +
  theme_bw() + theme(panel.border = element_blank(),
                     axis.line = element_line(colour = "grey"))

# WB
dim2_wb_acc_eu <- ggplot() +
  geom_boxplot(aes(year, wbgi_vae, group = year),
               data = DB_vdem_lib_dem_EU,
               outlier.color="grey",
               color="grey",
               varwidth = TRUE) +
  geom_line(aes(year, wbgi_vae, group = country_name, linetype = country_name), 
            data = DB_vdem_lib_dem_EU_subgroup) +  
  scale_x_continuous(breaks=c(1995,2000, 2005, 2010, 2015, 2020),
                     name = NULL) +
  scale_y_continuous(name="Accountability (WB)") +
  scale_linetype_manual(values=c("dotdash", "solid")) +
  theme(legend.position="bottom",legend.text=element_text(size=7),
        legend.title = element_blank())  +
  theme_bw() + theme(panel.border = element_blank(),
                     axis.line = element_line(colour = "grey"))

# Appendix (EU countries)
Figure_A12 <- ggarrange(ggarrange(dim2_vdem_acc_eu, dim2_db_acc_eu, dim2_wb_acc_eu, ncol = 3, nrow = 1, legend = "none"))

# BTI
dim2_bti_acc <- ggplot() +
  geom_boxplot(aes(year, `Executive Accountability`, group = year), 
               data = DB_vdem_lib_dem, 
               outlier.color="grey",
               color="grey",
               varwidth = TRUE) +
  geom_line(aes(year, `Executive Accountability`, group = country_name, linetype = country_name), 
            data = DB_vdem_lib_dem_subgroup) +  
  scale_linetype_manual(values=c("dotdash", "solid")) +
  scale_x_continuous(breaks=c(2015, 2020),
                     limits=c(2013.5, 2022.5),
                     name = NULL) +
  scale_y_continuous(name="Executive Accountability (BTI)") +
  theme(legend.position="bottom",legend.text=element_text(size=7),
        legend.title = element_blank())  +
  theme_bw() + theme(panel.border = element_blank(),
                     axis.line = element_line(colour = "grey"))

# BTI
dim2_bti_leg <- ggplot() +
  geom_boxplot(aes(year, `Legislative Actors' Resources`, group = year), 
               data = DB_vdem_lib_dem, 
               outlier.color="grey",
               color="grey",
               varwidth = TRUE) +
  geom_line(aes(year, `Legislative Actors' Resources`, group = country_name, linetype = country_name), 
            data = DB_vdem_lib_dem_subgroup) +  
  scale_linetype_manual(values=c("dotdash", "solid")) +
  scale_x_continuous(breaks=c(2015, 2020),
                     limits=c(2013.5, 2022.5),
                     name = NULL) +
  scale_y_continuous(name="Legislative Actors Resources (BTI)") +
  theme(legend.position="bottom",legend.text=element_text(size=7),
        legend.title = element_blank())  +
  theme_bw() + theme(panel.border = element_blank(),
                     axis.line = element_line(colour = "grey"))

# BTI
dim2_bti_ind <- ggplot() +
  geom_boxplot(aes(year, `Independent Supervisory Bodies`, group = year), 
               data = DB_vdem_lib_dem, 
               outlier.color="grey",
               color="grey",
               varwidth = TRUE) +
  geom_line(aes(year, `Independent Supervisory Bodies`, group = country_name, linetype = country_name), 
            data = DB_vdem_lib_dem_subgroup) +  
  scale_linetype_manual(values=c("dotdash", "solid")) +
  scale_x_continuous(breaks=c(2015, 2020),
                     limits=c(2013.5, 2022.5),
                     name = NULL) +
  scale_y_continuous(name="Independent Supervisory Bodies (BTI)") +
  theme(legend.position="bottom",legend.text=element_text(size=7),
        legend.title = element_blank())  +
  theme_bw() + theme(panel.border = element_blank(),
                     axis.line = element_line(colour = "grey"))

# IDEA
dim2_idea_elr <- ggplot() +
  geom_boxplot(aes(year, electoral_reforms, group = year),
               data = DB_vdem_lib_dem,
               outlier.color="grey",
               color="grey",
               varwidth = TRUE) +
  geom_line(aes(year, electoral_reforms, group = country_name, linetype = country_name), 
            data = DB_vdem_lib_dem_subgroup) +  
  scale_x_continuous(breaks=c(1995,2000, 2005, 2010, 2015, 2020),
                     name = NULL) +
  scale_y_continuous(name="Electoral Refroms (IDEA)") +
  scale_linetype_manual(values=c("dotdash", "solid")) +
  theme(legend.position="bottom",legend.text=element_text(size=7),
        legend.title = element_blank())  +
  theme_bw() + theme(panel.border = element_blank(),
                     axis.line = element_line(colour = "grey"))

# V-Dem
dim2_vdem_dia <- ggplot() +
  geom_boxplot(aes(year, v2x_diagacc, group = year), 
               data = DB_vdem_lib_dem, 
               outlier.color="grey",
               color="grey",
               varwidth = TRUE) +
  geom_line(aes(year, v2x_diagacc, group = country_name, linetype = country_name), 
            data = DB_vdem_lib_dem_subgroup) +  
  scale_x_continuous(breaks=c(1995,2000, 2005, 2010, 2015, 2020),
                     name = NULL) +
  scale_y_continuous(name="Diagonal Accountability (V-Dem)") +
  scale_linetype_manual(values=c("dotdash", "solid")) +
  theme(legend.position="bottom",legend.text=element_text(size=7),
        legend.title = element_blank())  +
  theme_bw() + theme(panel.border = element_blank(),
                     axis.line = element_line(colour = "grey"))

# Appendix (alternative measures)
Figure_A13 <- ggarrange(ggarrange(dim2_bti_acc, dim2_bti_leg, dim2_bti_ind, 
                                  dim2_idea_elr, dim2_vdem_dia,
                                  ncol = 3, nrow = 2, legend = "none"))

# All plots
Figure_2
Figure_A12
Figure_A13

###==== 3. Participation =====
# V-Dem
dim3_vdem_par <- ggplot() +
  geom_boxplot(aes(year, v2x_partip, group = year),
               data = DB_vdem_lib_dem,
               outlier.color="grey",
               color="grey",
               varwidth = TRUE) +
  geom_line(aes(year, v2x_partip, group = country_name, linetype = country_name), 
            data = DB_vdem_lib_dem_subgroup) +  
  scale_x_continuous(breaks=c(1995,2000, 2005, 2010, 2015, 2020),
                     name = NULL) +
  scale_y_continuous(name="Participation (V-Dem)") +
  scale_linetype_manual(values=c("dotdash", "solid")) +
  theme(legend.position="bottom",legend.text=element_text(size=7),
        legend.title = element_blank()) +
  theme_bw() + theme(panel.border = element_blank(),
                     axis.line = element_line(colour = "grey"))

# DB
dim3_db_par <- ggplot() +
  geom_boxplot(aes(year, PAR_EFPA, group = year),
               data = DB_vdem_lib_dem,
               outlier.color="grey",
               color="grey",
               varwidth = TRUE) +
  geom_line(aes(year, PAR_EFPA, group = country_name, linetype = country_name), 
            data = DB_vdem_lib_dem_subgroup) +  
  scale_x_continuous(breaks=c(1995,2000, 2005, 2010, 2015, 2020),
                     limits=c(1993.5, 2018),
                     name = NULL) +
  scale_y_continuous(name="Effective participation (DB)") +
  scale_linetype_manual(values=c("dotdash", "solid")) +
  theme(legend.position="bottom",legend.text=element_text(size=7),
        legend.title = element_blank()) +
  theme_bw() + theme(panel.border = element_blank(),
                     axis.line = element_line(colour = "grey"))

# FH
dim3_fh_par <- ggplot() +
  geom_boxplot(aes(year, fh_ppp, group = year),
               data = DB_vdem_lib_dem,
               outlier.color="grey",
               color="grey",
               varwidth = TRUE) +
  geom_line(aes(year, fh_ppp, group = country_name, linetype = country_name), 
            data = DB_vdem_lib_dem_subgroup) +  
  scale_x_continuous(breaks=c(2005, 2010, 2015, 2020),
                     limits = c(2003.5, 2021.5),
                     name = NULL) +
  scale_y_continuous(name="Political Pluralism and Participation (FH)") +
  scale_linetype_manual(values=c("dotdash", "solid")) +
  theme(legend.position="bottom",legend.text=element_text(size=7),
        legend.title = element_blank()) +
  theme_bw() + theme(panel.border = element_blank(),
                     axis.line = element_line(colour = "grey"))

# Main text
Figure_3 <- ggarrange(ggarrange(dim3_vdem_par, dim3_db_par, dim3_fh_par, nrow = 1, ncol = 3, legend = "none"))

# V-Dem
dim3_vdem_par_eu <- ggplot() +
  geom_boxplot(aes(year, v2x_partip, group = year),
               data = DB_vdem_lib_dem_EU,
               outlier.color="grey",
               color="grey",
               varwidth = TRUE) +
  geom_line(aes(year, v2x_partip, group = country_name, linetype = country_name), 
            data = DB_vdem_lib_dem_EU_subgroup) +  
  scale_x_continuous(breaks=c(1995,2000, 2005, 2010, 2015, 2020),
                     name = NULL) +
  scale_y_continuous(name="Participation (V-Dem)") +
  scale_linetype_manual(values=c("dotdash", "solid")) +
  theme(legend.position="bottom",legend.text=element_text(size=7),
        legend.title = element_blank()) +
  theme_bw() + theme(panel.border = element_blank(),
                     axis.line = element_line(colour = "grey"))

# DB
dim3_db_par_eu <- ggplot() +
  geom_boxplot(aes(year, PAR_EFPA, group = year),
               data = DB_vdem_lib_dem_EU,
               outlier.color="grey",
               color="grey",
               varwidth = TRUE) +
  geom_line(aes(year, PAR_EFPA, group = country_name, linetype = country_name), 
            data = DB_vdem_lib_dem_EU_subgroup) +  
  scale_x_continuous(breaks=c(1995,2000, 2005, 2010, 2015, 2020),
                     limits=c(1997, 2017),
                     name = NULL) +
  scale_y_continuous(name="Effective participation (DB)") +
  scale_linetype_manual(values=c("dotdash", "solid")) +
  theme(legend.position="bottom",legend.text=element_text(size=7),
        legend.title = element_blank()) +
  theme_bw() + theme(panel.border = element_blank(),
                     axis.line = element_line(colour = "grey"))

# FH
dim3_fh_par_eu <- ggplot() +
  geom_boxplot(aes(year, fh_ppp, group = year),
               data = DB_vdem_lib_dem_EU,
               outlier.color="grey",
               color="grey",
               varwidth = TRUE) +
  geom_line(aes(year, fh_ppp, group = country_name, linetype = country_name), 
            data = DB_vdem_lib_dem_EU_subgroup) +  
  scale_x_continuous(breaks=c(2000, 2005, 2010, 2015, 2020),
                     limits = c(2004.5, 2021.5),
                     name = NULL) +
  scale_y_continuous(name="Political pluralism and participation (FH)") +
  scale_linetype_manual(values=c("dotdash", "solid")) +
  theme(legend.position="bottom",legend.text=element_text(size=7),
        legend.title = element_blank()) +
  theme_bw() + theme(panel.border = element_blank(),
                     axis.line = element_line(colour = "grey"))

# Appendix (EU countries)
Figure_A14 <- ggarrange(ggarrange(dim3_vdem_par_eu, dim3_db_par_eu, dim3_fh_par_eu, ncol = 3, nrow = 1, legend = "none"))

# V-Dem
dim3_vdem_mas <- ggplot() +
  geom_boxplot(aes(year, v2cagenmob, group = year),
               data = DB_vdem_lib_dem_EU,
               outlier.color="grey",
               color="grey",
               varwidth = TRUE) +
  geom_line(aes(year, v2cagenmob, group = country_name, linetype = country_name), 
            data = DB_vdem_lib_dem_EU_subgroup) +  
  scale_x_continuous(breaks=c(1995,2000, 2005, 2010, 2015, 2020),
                     name = NULL) +
  scale_y_continuous(name="Mass mobilization (V-Dem)") +
  scale_linetype_manual(values=c("dotdash", "solid")) +
  theme(legend.position="bottom",legend.text=element_text(size=7),
        legend.title = element_blank()) +
  theme_bw() + theme(panel.border = element_blank(),
                     axis.line = element_line(colour = "grey"))

# Vanhanen
dim3_van_par <- ggplot() +
  geom_boxplot(aes(year, van_part, group = year),
               data = DB_vdem_lib_dem,
               outlier.color="grey",
               color="grey",
               varwidth = TRUE) +
  geom_line(aes(year, van_part, group = country_name, linetype = country_name), 
            data = DB_vdem_lib_dem_subgroup) +  
  scale_x_continuous(breaks=c(1995,2000, 2005, 2010, 2015, 2020),
                     name = NULL) +
  scale_y_continuous(name="Participation Index (Vanhanen)") +
  scale_linetype_manual(values=c("dotdash", "solid")) +
  theme(legend.position="bottom",legend.text=element_text(size=7),
        legend.title = element_blank()) +
  theme_bw() + theme(panel.border = element_blank(),
                     axis.line = element_line(colour = "grey"))

# IDEA
dim3_idea_tur <- ggplot() +
  geom_boxplot(aes(year, turnout, group = year),
               data = DB_vdem_lib_dem,
               outlier.color="grey",
               color="grey",
               varwidth = TRUE) +
  geom_line(aes(year, turnout, group = country_name, linetype = country_name), 
            data = DB_vdem_lib_dem_subgroup) +  
  scale_x_continuous(breaks=c(1995,2000, 2005, 2010, 2015, 2020),
                     name = NULL) +
  scale_y_continuous(name="Turnout (IDEA)") +
  scale_linetype_manual(values=c("dotdash", "solid")) +
  theme(legend.position="bottom",legend.text=element_text(size=7),
        legend.title = element_blank()) +
  theme_bw() + theme(panel.border = element_blank(),
                     axis.line = element_line(colour = "grey"))

# VTD
dim3_vdt_ept <- ggplot() +
  geom_boxplot(aes(year, ideavt_euvt, group = year),
               data = DB_vdem_lib_dem,
               outlier.color="grey",
               color="grey",
               varwidth = TRUE) +
  geom_line(aes(year, ideavt_euvt, group = country_name, linetype = country_name), 
            data = DB_vdem_lib_dem_subgroup) +  
  scale_x_continuous(breaks=c(1995,2000, 2005, 2010, 2015, 2020),
                     name = NULL) +
  scale_y_continuous(name="Turnout EP Elections (VTD)") +
  scale_linetype_manual(values=c("dotdash", "solid")) +
  theme(legend.position="bottom",legend.text=element_text(size=7),
        legend.title = element_blank()) +
  theme_bw() + theme(panel.border = element_blank(),
                     axis.line = element_line(colour = "grey"))

# Alternative indicators
Figure_A15 <- ggarrange(ggarrange(dim3_vdem_mas, dim3_van_par, dim3_idea_tur, 
                                  dim3_vdt_ept, ncol = 2, nrow = 2, legend = "none"))

# All plots
Figure_3
Figure_A14
Figure_A15

###==== 4. Competition =====
# PSGO
dim4_psgo_clo <- ggplot() +
  geom_boxplot(aes(year, closure_c, group = year),
               data = DB_vdem_lib_dem,
               outlier.color="grey",
               color="grey",
               varwidth = TRUE) +
  geom_line(aes(year, closure_c, group = country_name, linetype = country_name), 
            data = DB_vdem_lib_dem_subgroup) +  
  scale_x_continuous(breaks=c(1995, 2000, 2005, 2010, 2015, 2020),
                     limits=c(1993.5, 2018.5),
                     name = NULL) +
  scale_y_continuous(name="Party system closure (PSGO)") +
  scale_linetype_manual(values=c("dotdash", "solid")) +
  theme(legend.position="bottom",legend.text=element_text(size=7),
        legend.title = element_blank()) +
  theme_bw() + theme(panel.border = element_blank(),
                     axis.line = element_line(colour = "grey"))

# DEV
dim4_dev_vol <- ggplot() +
  geom_boxplot(aes(year, volatility, group = year),
               data = DB_vdem_lib_dem,
               outlier.color="grey",
               color="grey",
               varwidth = TRUE) +
  geom_line(aes(year, volatility, group = country_name, linetype = country_name), 
            data = DB_vdem_lib_dem_subgroup) +  
  scale_x_continuous(breaks=c(1995,2000, 2005, 2010, 2015, 2020),
                     limits=c(1993.5, 2018.5),
                     name = NULL) +
  scale_y_continuous(name="Volatility (DEV)") +
  scale_linetype_manual(values=c("dotdash", "solid")) +
  theme(legend.position="bottom",legend.text=element_text(size=7),
        legend.title = element_blank()) + 
  theme_bw() + theme(panel.border = element_blank(),
                     axis.line = element_line(colour = "grey"))

# Emanuele
dim4_ema_inn <- ggplot() +
  geom_boxplot(aes(year, psi_psi1, group = year),
               data = DB_vdem_lib_dem,
               outlier.color="grey",
               color="grey",
               varwidth = TRUE) +
  geom_line(aes(year, psi_psi1, group = country_name, linetype = country_name), 
            data = DB_vdem_lib_dem_subgroup) +  
  scale_x_continuous(breaks=c(1995, 2000, 2005, 2010, 2015, 2020),
                     limits=c(1993.5, 2018.5),
                     name = NULL) +
  scale_y_continuous(name="PS innovation (Emanuele)") +
  scale_linetype_manual(values=c("dotdash", "solid")) +
  theme(legend.position="bottom",legend.text=element_text(size=7),
        legend.title = element_blank()) +
  theme_bw() + theme(panel.border = element_blank(),
                     axis.line = element_line(colour = "grey"))

# Main text
Figure_4 <- ggarrange(ggarrange(dim4_psgo_clo, dim4_dev_vol, dim4_ema_inn, 
                                ncol = 3, nrow = 1, legend = "none"))

# PSGO
dim4_psgo_clo_eu <- ggplot() +
  geom_boxplot(aes(year, closure_c, group = year),
               data = DB_vdem_lib_dem_EU,
               outlier.color="grey",
               color="grey",
               varwidth = TRUE) +
  geom_line(aes(year, closure_c, group = country_name, linetype = country_name), 
            data = DB_vdem_lib_dem_EU_subgroup) +  
  scale_x_continuous(breaks=c(1995, 2000, 2005, 2010, 2015, 2020),
                     limits=c(1993.5, 2018.5),
                     name = NULL) +
  scale_y_continuous(name="Party system closure (PSGO)") +
  scale_linetype_manual(values=c("dotdash", "solid")) +
  theme(legend.position="bottom",legend.text=element_text(size=7),
        legend.title = element_blank()) +
  theme_bw() + theme(panel.border = element_blank(),
                     axis.line = element_line(colour = "grey"))

# Emanuele
dim4_dev_vol_eu <- ggplot() +
  geom_boxplot(aes(year, volatility, group = year),
               data = DB_vdem_lib_dem_EU,
               outlier.color="grey",
               color="grey",
               varwidth = TRUE) +
  geom_line(aes(year, volatility, group = country_name, linetype = country_name), 
            data = DB_vdem_lib_dem_EU_subgroup) +  
  scale_x_continuous(breaks=c(1995,2000, 2005, 2010, 2015, 2020),
                     limits=c(1993.5, 2018.5),
                     name = NULL) +
  scale_y_continuous(name="Volatility (DEV)") +
  scale_linetype_manual(values=c("dotdash", "solid")) +
  theme(legend.position="bottom",legend.text=element_text(size=7),
        legend.title = element_blank()) +
  theme_bw() + theme(panel.border = element_blank(),
                     axis.line = element_line(colour = "grey"))

# Emanuele
dim4_ema_inn_eu <- ggplot() +
  geom_boxplot(aes(year, psi_psi1, group = year),
               data = DB_vdem_lib_dem_EU,
               outlier.color="grey",
               color="grey",
               varwidth = TRUE) +
  geom_line(aes(year, psi_psi1, group = country_name, linetype = country_name), 
            data = DB_vdem_lib_dem_EU_subgroup) +  
  scale_x_continuous(breaks=c(1995, 2000, 2005, 2010, 2015, 2020),
                     limits=c(1993.5, 2018.5),
                     name = NULL) +
  scale_y_continuous(name="PS innovation (Emanuele)") +
  scale_linetype_manual(values=c("dotdash", "solid")) +
  theme(legend.position="bottom",legend.text=element_text(size=7),
        legend.title = element_blank()) +
  theme_bw() + theme(panel.border = element_blank(),
                     axis.line = element_line(colour = "grey"))

Figure_A16 <- ggarrange(ggarrange(dim4_psgo_clo_eu, dim4_dev_vol_eu, dim4_ema_inn_eu, 
                                  ncol = 3, nrow = 1, legend = "none"))

# DB
dim4_db_com <- ggplot() +
  geom_boxplot(aes(year, COMPET, group = year),
               data = DB_vdem_lib_dem,
               outlier.color="grey",
               color="grey",
               varwidth = TRUE) +
  geom_line(aes(year, COMPET, group = country_name, linetype = country_name), 
            data = DB_vdem_lib_dem_subgroup) +  
  scale_x_continuous(breaks=c(1995, 2000, 2005, 2010, 2015, 2020),
                     limits=c(1994.5, 2018.5),
                     name = NULL) +
  scale_y_continuous(name="Competition (DB)") +
  scale_linetype_manual(values=c("dotdash", "solid")) +
  theme(legend.position="bottom",legend.text=element_text(size=7),
        legend.title = element_blank()) +
  theme_bw() + theme(panel.border = element_blank(),
                     axis.line = element_line(colour = "grey"))

# Vanhanen
dim4_van_com <- ggplot() +
  geom_boxplot(aes(year, van_comp, group = year),
               data = DB_vdem_lib_dem,
               outlier.color="grey",
               color="grey",
               varwidth = TRUE) +
  geom_line(aes(year, van_comp, group = country_name, linetype = country_name), 
            data = DB_vdem_lib_dem_subgroup) +  
  scale_x_continuous(breaks=c(1995, 2000, 2005, 2010, 2015, 2020),
                     limits=c(1994.5, 2018.5),
                     name = NULL) +
  scale_y_continuous(name="Competition (Vanhanen)") +
  scale_linetype_manual(values=c("dotdash", "solid")) +
  theme(legend.position="bottom",legend.text=element_text(size=7),
        legend.title = element_blank()) +
  theme_bw() + theme(panel.border = element_blank(),
                     axis.line = element_line(colour = "grey"))

# PSGO
dim4_psgo_enep <- ggplot() +
  geom_boxplot(aes(year, enep, group = year),
               data = DB_vdem_lib_dem,
               outlier.color="grey",
               color="grey",
               varwidth = TRUE) +
  geom_line(aes(year, enep, group = country_name, linetype = country_name), 
            data = DB_vdem_lib_dem_subgroup) +  
  scale_x_continuous(breaks=c(1995,2000, 2005, 2010, 2015, 2020),
                     limits=c(1993.5, 2018.5),
                     name = NULL) +
  scale_y_continuous(name="Electoral fragmentation (PSGO)") +
  scale_linetype_manual(values=c("dotdash", "solid")) +
  theme(legend.position="bottom",legend.text=element_text(size=7),
        legend.title = element_blank()) +
  theme_bw() + theme(panel.border = element_blank(),
                     axis.line = element_line(colour = "grey"))

# CPD
dim4_cpd_fra <- ggplot() +
  geom_boxplot(aes(year, cpds_frleg, group = year),
               data = DB_vdem_lib_dem,
               outlier.color="grey",
               color="grey",
               varwidth = TRUE) +
  geom_line(aes(year, cpds_frleg, group = country_name, linetype = country_name), 
            data = DB_vdem_lib_dem_subgroup) +  
  scale_x_continuous(breaks=c(1995, 2000, 2005, 2010, 2015, 2020),
                     limits=c(1993.5, 2018.5),
                     name = NULL) +
  scale_y_continuous(name="Legislative fract. party system (Rae/CPD)") +
  scale_linetype_manual(values=c("dotdash", "solid")) +
  theme(legend.position="bottom",legend.text=element_text(size=7),
        legend.title = element_blank()) +
  theme_bw() + theme(panel.border = element_blank(),
                     axis.line = element_line(colour = "grey"))

# DEV
dim4_dev_evol <- ggplot() +
  geom_boxplot(aes(year, evep_tv, group = year),
               data = DB_vdem_lib_dem,
               outlier.color="grey",
               color="grey",
               varwidth = TRUE) +
  geom_line(aes(year, evep_tv, group = country_name, linetype = country_name), 
            data = DB_vdem_lib_dem_subgroup) +  
  scale_x_continuous(breaks=c(1995, 2000, 2005, 2010, 2015, 2020),
                     limits=c(1993.5, 2018.5),
                     name = NULL) +
  scale_y_continuous(name="Total volatility EP (DEV)") +
  scale_linetype_manual(values=c("dotdash", "solid")) +
  theme(legend.position="bottom",legend.text=element_text(size=7),
        legend.title = element_blank()) +
  theme_bw() + theme(panel.border = element_blank(),
                     axis.line = element_line(colour = "grey"))

# Appendix (alternative measures)
Figure_A17 <- ggarrange(ggarrange(dim4_db_com, dim4_van_com, dim4_psgo_enep, 
                                  dim4_cpd_fra, dim4_dev_evol, ncol = 3,
                                  nrow = 2, legend = "none"))

# All plots
Figure_4
Figure_A16
Figure_A17

###==== 5. Freedoms =====
# V-Dem
dim5_vdem_kil <- ggplot() +
  geom_boxplot(aes(year, v2clkill, group = year),
               data = DB_vdem_lib_dem,
               outlier.color="grey",
               color="grey",
               varwidth = TRUE) +
  geom_line(aes(year, v2clkill, group = country_name, linetype = country_name), 
            data = DB_vdem_lib_dem_subgroup) +  
  scale_x_continuous(breaks=c(1995,2000, 2005, 2010, 2015, 2020),
                     name = NULL) +
  scale_y_continuous(name="Freedom from political killings (V-Dem)") +
  scale_linetype_manual(values=c("dotdash", "solid")) +
  theme(legend.position="bottom",legend.text=element_text(size=7),
        legend.title = element_blank()) +
  theme_bw() + theme(panel.border = element_blank(),
                     axis.line = element_line(colour = "grey"))

# V-Dem
dim5_vdem_wla <- ggplot() +
  geom_boxplot(aes(year, v2clslavef, group = year),
               data = DB_vdem_lib_dem,
               outlier.color="grey",
               color="grey",
               varwidth = TRUE) +
  geom_line(aes(year, v2clslavef, group = country_name, linetype = country_name), 
            data = DB_vdem_lib_dem_subgroup) +  
  scale_x_continuous(breaks=c(1995,2000, 2005, 2010, 2015, 2020),
                     name = NULL) +
  scale_y_continuous(name="Freedom from forced labor for women (V-Dem)") +
  scale_linetype_manual(values=c("dotdash", "solid")) +
  theme(legend.position="bottom",legend.text=element_text(size=7),
        legend.title = element_blank()) +
  theme_bw() + theme(panel.border = element_blank(),
                     axis.line = element_line(colour = "grey"))

# V-Dem
dim5_vdem_acd <- ggplot() +
  geom_boxplot(aes(year, v2clacfree, group = year),
               data = DB_vdem_lib_dem,
               outlier.color="grey",
               color="grey",
               varwidth = TRUE) +
  geom_line(aes(year, v2clacfree, group = country_name, linetype = country_name), 
            data = DB_vdem_lib_dem_subgroup) +  
  scale_x_continuous(breaks=c(1995,2000, 2005, 2010, 2015, 2020),
                     name = NULL) +
  scale_y_continuous(name="Freedom of academic discussion (V-Dem)") +
  scale_linetype_manual(values=c("dotdash", "solid")) +
  theme(legend.position="bottom",legend.text=element_text(size=7),
        legend.title = element_blank()) +
  theme_bw() + theme(panel.border = element_blank(),
                     axis.line = element_line(colour = "grey"))

# Main text
Figure_5 <- ggarrange(ggarrange(dim5_vdem_kil, dim5_vdem_wla, dim5_vdem_acd, ncol = 3, nrow = 1, legend = "none")
)

# V-Dem
dim5_vdem_kil_eu <- ggplot() +
  geom_boxplot(aes(year, v2clkill, group = year),
               data = DB_vdem_lib_dem_EU,
               outlier.color="grey",
               color="grey",
               varwidth = TRUE) +
  geom_line(aes(year, v2clkill, group = country_name, linetype = country_name), 
            data = DB_vdem_lib_dem_EU_subgroup) +  
  scale_x_continuous(breaks=c(1995,2000, 2005, 2010, 2015, 2020),
                     name = NULL) +
  scale_y_continuous(name="Freedom from political killings (V-Dem)") +
  scale_linetype_manual(values=c("dotdash", "solid")) +
  theme(legend.position="bottom",legend.text=element_text(size=7),
        legend.title = element_blank()) +
  theme_bw() + theme(panel.border = element_blank(),
                     axis.line = element_line(colour = "grey"))

# V-Dem
dim5_vdem_wla_eu <- ggplot() +
  geom_boxplot(aes(year, v2clslavef, group = year),
               data = DB_vdem_lib_dem_EU,
               outlier.color="grey",
               color="grey",
               varwidth = TRUE) +
  geom_line(aes(year, v2clslavef, group = country_name, linetype = country_name), 
            data = DB_vdem_lib_dem_EU_subgroup) +  
  scale_x_continuous(breaks=c(1995,2000, 2005, 2010, 2015, 2020),
                     name = NULL) +
  scale_y_continuous(name="Freedom from forced labor for women (V-Dem)") +
  scale_linetype_manual(values=c("dotdash", "solid")) +
  theme(legend.position="bottom",legend.text=element_text(size=7),
        legend.title = element_blank()) +
  theme_bw() + theme(panel.border = element_blank(),
                     axis.line = element_line(colour = "grey"))

# V-Dem
dim5_vdem_acd_eu <- ggplot() +
  geom_boxplot(aes(year, v2clacfree, group = year),
               data = DB_vdem_lib_dem_EU,
               outlier.color="grey",
               color="grey",
               varwidth = TRUE) +
  geom_line(aes(year, v2clacfree, group = country_name, linetype = country_name), 
            data = DB_vdem_lib_dem_EU_subgroup) +  
  scale_x_continuous(breaks=c(1995,2000, 2005, 2010, 2015, 2020),
                     name = NULL) +
  scale_y_continuous(name="Freedom of academic discussion (V-Dem)") +
  scale_linetype_manual(values=c("dotdash", "solid")) +
  theme(legend.position="bottom",legend.text=element_text(size=7),
        legend.title = element_blank()) +
  theme_bw() + theme(panel.border = element_blank(),
                     axis.line = element_line(colour = "grey"))

# Appendix (EU countries)
Figure_A18 <- ggarrange(ggarrange(dim5_vdem_kil_eu, dim5_vdem_wla_eu, dim5_vdem_acd_eu, ncol = 3,
                                  nrow= 1, legend = "none"))

# V-Dem
dim5_vdem_tor <- ggplot() +
  geom_boxplot(aes(year, v2cltort, group = year),
               data = DB_vdem_lib_dem,
               outlier.color="grey",
               color="grey",
               varwidth = TRUE) +
  geom_line(aes(year, v2cltort, group = country_name, linetype = country_name), 
            data = DB_vdem_lib_dem_subgroup) +  
  scale_x_continuous(breaks=c(1995,2000, 2005, 2010, 2015, 2020),
                     name = NULL) +
  scale_y_continuous(name="Freedom from torture (V-Dem)") +
  scale_linetype_manual(values=c("dotdash", "solid")) +
  theme(legend.position="bottom",legend.text=element_text(size=7),
        legend.title = element_blank()) +
  theme_bw() + theme(panel.border = element_blank(),
                     axis.line = element_line(colour = "grey"))

# V-Dem
dim5_vdem_eco <- ggplot() +
  geom_boxplot(aes(year, v2clstown, group = year),
               data = DB_vdem_lib_dem,
               outlier.color="grey",
               color="grey",
               varwidth = TRUE) +
  geom_line(aes(year, v2clstown, group = country_name, linetype = country_name), 
            data = DB_vdem_lib_dem_subgroup) +  
  scale_x_continuous(breaks=c(1995,2000, 2005, 2010, 2015, 2020),
                     name = NULL) +
  scale_y_continuous(name="State ownership of economy (V-Dem)") +
  scale_linetype_manual(values=c("dotdash", "solid")) +
  theme(legend.position="bottom",legend.text=element_text(size=7),
        legend.title = element_blank()) +
  theme_bw() + theme(panel.border = element_blank(),
                     axis.line = element_line(colour = "grey"))

# FoP
dim5_fop_fop <- ggplot() +
  geom_boxplot(aes(year, fhp_score5, group = year),
               data = DB_vdem_lib_dem,
               outlier.color="grey",
               color="grey",
               varwidth = TRUE) +
  geom_line(aes(year, fhp_score5, group = country_name, linetype = country_name), 
            data = DB_vdem_lib_dem_subgroup) +  
  scale_x_continuous(breaks=c(2005, 2010, 2015),
                     limits=c(2000, 2017),
                     name = NULL) +
  scale_y_continuous(name="Freedom of the Press (FoP)") +
  scale_linetype_manual(values=c("dotdash", "solid")) +
  theme(legend.position="bottom",legend.text=element_text(size=7),
        legend.title = element_blank()) +
  theme_bw() + theme(panel.border = element_blank(),
                     axis.line = element_line(colour = "grey"))

# FH
dim5_fh_free <- ggplot() +
  geom_boxplot(aes(year, fh_feb, group = year),
               data = DB_vdem_lib_dem,
               outlier.color="grey",
               color="grey",
               varwidth = TRUE) +
  geom_line(aes(year, fh_feb, group = country_name, linetype = country_name), 
            data = DB_vdem_lib_dem_subgroup) +  
  scale_x_continuous(breaks=c(2000, 2005, 2010, 2015, 2020),
                     limits=c(2003.5, 2021.5),
                     name = NULL) +
  scale_y_continuous(name="Freedom of Expression and Belief (FH)") +
  scale_linetype_manual(values=c("dotdash", "solid")) +
  theme(legend.position="bottom",legend.text=element_text(size=7),
        legend.title = element_blank()) +
  theme_bw() + theme(panel.border = element_blank(),
                     axis.line = element_line(colour = "grey"))

# BTI
dim5_bti_civ <- ggplot() +
  geom_boxplot(aes(year, `Civil Rights and Political Liberties`, group = year),
               data = DB_vdem_lib_dem,
               outlier.color="grey",
               color="grey",
               varwidth = TRUE) +
  geom_line(aes(year, `Civil Rights and Political Liberties`, group = country_name, linetype = country_name), 
            data = DB_vdem_lib_dem_subgroup) +  
  scale_x_continuous(breaks=c(2015, 2020),
                     limits=c(2013.5, 2022.5),
                     name = NULL) +
  scale_y_continuous(name="Civil Rights and Political Liberties (BTI)") +
  scale_linetype_manual(values=c("dotdash", "solid")) +
  theme(legend.position="bottom",legend.text=element_text(size=7),
        legend.title = element_blank()) +
  theme_bw() + theme(panel.border = element_blank(),
                     axis.line = element_line(colour = "grey"))

# Appendix (alternative measures)
Figure_A19 <- ggarrange(ggarrange(dim5_vdem_tor, dim5_vdem_eco, dim5_fop_fop, 
                                            dim5_fh_free, dim5_bti_civ, 
                                            ncol = 3,
                                            nrow = 2, 
                                            legend = "none"))

# All freedoms plots
Figure_5
Figure_A18
Figure_A19

### ==== 6. Equality =====
# CLIO
dim6_cli_edu <- ggplot() +
  geom_boxplot(aes(year, e_peaveduc, group = year),
               data = DB_vdem_lib_dem,
               outlier.color="grey",
               color="grey",
               varwidth = TRUE) +
  geom_line(aes(year, e_peaveduc, group = country_name, linetype = country_name), 
            data = DB_vdem_lib_dem_subgroup) +  
  scale_x_continuous(breaks=c(1995,2000, 2005, 2010, 2015, 2020),
                     name = NULL) +
  scale_y_continuous(name="Education 15+ (CLIO)") +
  scale_linetype_manual(values=c("dotdash", "solid")) +
  theme(legend.position="bottom",legend.text=element_text(size=7),
        legend.title = element_blank()) +
  theme_bw() + theme(panel.border = element_blank(),
                     axis.line = element_line(colour = "grey"))

# LIS
dim6_lis_gin <- ggplot() +
  geom_boxplot(aes(year, income_gini, group = year),
               data = DB_vdem_lib_dem,
               outlier.color="grey",
               color="grey",
               varwidth = TRUE) +
  geom_line(aes(year, income_gini, group = country_name, linetype = country_name), 
            data = DB_vdem_lib_dem_subgroup %>% filter(year < 2021)) +  
  scale_x_continuous(breaks=c(1995,2000, 2005, 2010, 2015, 2020),
                     name = NULL) +
  scale_y_continuous(name="Income gini (LIS)",
                     limits = c(0.2, 0.45)) +
  scale_linetype_manual(values=c("dotdash", "solid")) +
  theme(legend.position="bottom",legend.text=element_text(size=7),
        legend.title = element_blank()) +
  theme_bw() + theme(panel.border = element_blank(),
                     axis.line = element_line(colour = "grey"))

# V-Dem
dim6_vdem_ele <- ggplot() +
  geom_boxplot(aes(year, v2elsnlsff, group = year),
               data = DB_vdem_lib_dem,
               outlier.color="grey",
               color="grey",
               varwidth = TRUE) +
  geom_line(aes(year, v2elsnlsff, group = country_name, linetype = country_name), 
            data = DB_vdem_lib_dem_subgroup) +  
  scale_x_continuous(breaks=c(1995,2000, 2005, 2010, 2015, 2020),
                     name = NULL) +
  scale_y_continuous(name="Subnational election eveness (V-Dem)") +
  scale_linetype_manual(values=c("dotdash", "solid")) +
  theme(legend.position="bottom",legend.text=element_text(size=7),
        legend.title = element_blank()) +
  theme_bw() + theme(panel.border = element_blank(),
                     axis.line = element_line(colour = "grey"))

# Main text
Figure_6 <- ggarrange(ggarrange(dim6_cli_edu, dim6_lis_gin, dim6_vdem_ele, 
                                ncol = 3, legend = "none"), nrow = 1)

# CLIO
dim6_cli_edu_eu <- ggplot() +
  geom_boxplot(aes(year, e_peaveduc, group = year),
               data = DB_vdem_lib_dem_EU,
               outlier.color="grey",
               color="grey",
               varwidth = TRUE) +
  geom_line(aes(year, e_peaveduc, group = country_name, linetype = country_name), 
            data = DB_vdem_lib_dem_EU_subgroup) +  
  scale_x_continuous(breaks=c(1995,2000, 2005, 2010, 2015, 2020),
                     name = NULL) +
  scale_y_continuous(name="Education 15+ (CLIO)") +
  scale_linetype_manual(values=c("dotdash", "solid")) +
  theme(legend.position="bottom",legend.text=element_text(size=7),
        legend.title = element_blank()) +
  theme_bw() + theme(panel.border = element_blank(),
                     axis.line = element_line(colour = "grey"))

# LIS
dim6_lis_gin_eu <- ggplot() +
  geom_boxplot(aes(year, income_gini, group = year),
               data = DB_vdem_lib_dem_EU,
               outlier.color="grey",
               color="grey",
               varwidth = TRUE) +
  geom_line(aes(year, income_gini, group = country_name, linetype = country_name), 
            data = DB_vdem_lib_dem_EU_subgroup %>% filter(year < 2021)) +  
  scale_x_continuous(breaks=c(1995,2000, 2005, 2010, 2015, 2020),
                     name = NULL) +
  scale_y_continuous(name="Income gini (LIS)",
                     limits = c(0.2, 0.45)) +
  scale_linetype_manual(values=c("dotdash", "solid")) +
  theme(legend.position="bottom",legend.text=element_text(size=7),
        legend.title = element_blank()) +
  theme_bw() + theme(panel.border = element_blank(),
                     axis.line = element_line(colour = "grey"))

# V-Dem
dim6_vdem_ele_eu <- ggplot() +
  geom_boxplot(aes(year, v2elsnlsff, group = year),
               data = DB_vdem_lib_dem_EU,
               outlier.color="grey",
               color="grey",
               varwidth = TRUE) +
  geom_line(aes(year, v2elsnlsff, group = country_name, linetype = country_name), 
            data = DB_vdem_lib_dem_EU_subgroup) +  
  scale_x_continuous(breaks=c(1995,2000, 2005, 2010, 2015, 2020),
                     name = NULL) +
  scale_y_continuous(name="Subnational election eveness (V-Dem)") +
  scale_linetype_manual(values=c("dotdash", "solid")) +
  theme(legend.position="bottom",legend.text=element_text(size=7),
        legend.title = element_blank()) +
  theme_bw() + theme(panel.border = element_blank(),
                     axis.line = element_line(colour = "grey"))

# Appendix (EU countries)
Figure_A20 <- ggarrange(ggarrange(dim6_cli_edu_eu, dim6_lis_gin_eu, 
                                  dim6_vdem_ele_eu, ncol = 3, legend = "none"),
                        nrow = 1)

# V-Dem
dim6_vdem_hea <- ggplot() +
  geom_boxplot(aes(year, v2pehealth, group = year),
               data = DB_vdem_lib_dem,
               outlier.color="grey",
               color="grey",
               varwidth = TRUE) +
  geom_line(aes(year, v2pehealth, group = country_name, linetype = country_name), 
            data = DB_vdem_lib_dem_subgroup) +  
  scale_x_continuous(breaks=c(1995,2000, 2005, 2010, 2015, 2020),
                     name = NULL) +
  scale_y_continuous(name="Health inequality (V-Dem)") +
  scale_linetype_manual(values=c("dotdash", "solid")) +
  theme(legend.position="bottom",legend.text=element_text(size=7),
        legend.title = element_blank()) +
  theme_bw() + theme(panel.border = element_blank(),
                     axis.line = element_line(colour = "grey"))

# UN
dim6_un_gen <- ggplot() +
  geom_boxplot(aes(year, gii_gii, group = year),
               data = DB_vdem_lib_dem,
               outlier.color="grey",
               color="grey",
               varwidth = TRUE) +
  geom_line(aes(year, gii_gii, group = country_name, linetype = country_name), 
            data = DB_vdem_lib_dem_subgroup) +  
  scale_x_continuous(breaks=c(1995,2000, 2005, 2010, 2015, 2020),
                     name = NULL) +
  scale_y_continuous(name="Gender Inequality Index (UN)") +
  scale_linetype_manual(values=c("dotdash", "solid")) +
  theme(legend.position="bottom",legend.text=element_text(size=7),
        legend.title = element_blank()) +
  theme_bw() + theme(panel.border = element_blank(),
                     axis.line = element_line(colour = "grey"))

# CSP
dim6_csp_gin <- ggplot() +
  geom_boxplot(aes(year, oecd_incinequal_t1a, group = year),
               data = DB_vdem_lib_dem,
               outlier.color="grey",
               color="grey",
               varwidth = TRUE) +
  geom_line(aes(year, oecd_incinequal_t1a, group = country_name, linetype = country_name), 
            data = DB_vdem_lib_dem_subgroup %>% filter(year < 2021)) +  
  scale_x_continuous(breaks=c(1995,2000, 2005, 2010, 2015, 2020),
                     limits = c(1992, 2018),
                     name = NULL) +
  scale_y_continuous(name="Income gini (CSP)",
                     limits = c(0.2, 0.45)) +
  scale_linetype_manual(values=c("dotdash", "solid")) +
  theme(legend.position="bottom",legend.text=element_text(size=7),
        legend.title = element_blank()) +
  theme_bw() + theme(panel.border = element_blank(),
                     axis.line = element_line(colour = "grey"))

# BTI
dim6_bti_inc <- ggplot() +
  geom_boxplot(aes(year, `Social Inclusion`, group = year),
               data = DB_vdem_lib_dem,
               outlier.color="grey",
               color="grey",
               varwidth = TRUE) +
  geom_line(aes(year,  `Social Inclusion`, group = country_name, linetype = country_name), 
            data = DB_vdem_lib_dem_subgroup) +  
  scale_x_continuous(breaks=c(2015, 2020),
                     limits = c(2013, 2022.5),
                     name = NULL) +
  scale_y_continuous(name=" Social Inclusion (BTI)") +
  scale_linetype_manual(values=c("dotdash", "solid")) +
  theme(legend.position="bottom",legend.text=element_text(size=7),
        legend.title = element_blank()) +
  theme_bw() + theme(panel.border = element_blank(),
                     axis.line = element_line(colour = "grey"))

# BTI
dim6_bti_hea <- ggplot() +
  geom_boxplot(aes(year, `Health`, group = year),
               data = DB_vdem_lib_dem,
               outlier.color="grey",
               color="grey",
               varwidth = TRUE) +
  geom_line(aes(year,  `Health`, group = country_name, linetype = country_name),
            data = DB_vdem_lib_dem_subgroup) +
  scale_x_continuous(breaks=c(2015, 2020),
                     limits = c(2013, 2022.5),
                     name = NULL) +
  scale_y_continuous(name="Health (BTI)") +
  scale_linetype_manual(values=c("dotdash", "solid")) +
  theme(legend.position="bottom",legend.text=element_text(size=7),
        legend.title = element_blank()) +
  theme_bw() + theme(panel.border = element_blank(),
                     axis.line = element_line(colour = "grey"))

# Appendix (alternative measures)
Figure_A21 <- ggarrange(ggarrange(dim6_vdem_hea, dim6_un_gen, dim6_csp_gin, dim6_bti_inc, dim6_bti_hea, 
                                        ncol = 3, nrow = 2, legend = "none"))

# All plots
Figure_6
Figure_A20
Figure_A21

###==== 7. Responsiveness =====
# DB
dim7_db_iss <- ggplot() +
  geom_boxplot(aes(year, Issuecongr, group = year),
               data = DB_vdem_lib_dem,
               outlier.color="grey",
               color="grey",
               varwidth = TRUE) +
  geom_line(aes(year, Issuecongr, group = country_name, linetype = country_name), 
            data = DB_vdem_lib_dem_subgroup) +  
  scale_x_continuous(breaks=c(1995,2000, 2005, 2010, 2015, 2020),
                     limits=c(1995.5, 2018),
                     name = NULL) +
  scale_y_continuous(name="Left-right issue congruence (DB)") +
  scale_linetype_manual(values=c("dotdash", "solid")) +
  theme(legend.position="bottom",legend.text=element_text(size=7),
        legend.title = element_blank()) +
  theme_bw() + theme(panel.border = element_blank(),
                     axis.line = element_line(colour = "grey"))

# CPP
dim7_cpp_ple <- ggplot() +
  geom_boxplot(aes(year, fulfil2, group = year),
               data = DB_vdem_lib_dem,
               outlier.color="grey",
               color="grey",
               varwidth = TRUE) +
  geom_line(aes(year, fulfil2, group = country_name, linetype = country_name), 
            data = DB_vdem_lib_dem_subgroup) +  
  scale_x_continuous(breaks=c(1995,2000, 2005, 2010, 2015, 2020),
                     name = NULL) +
  scale_y_continuous(name="Party pledge fulfillment (CPP)") +
  scale_linetype_manual(values=c("dotdash", "solid")) +
  theme(legend.position="bottom",legend.text=element_text(size=7),
        legend.title = element_blank()) +
  theme_bw() + theme(panel.border = element_blank(),
                     axis.line = element_line(colour = "grey"))

# HUMAN
dim7_hum_dsa <- ggplot() +
  geom_boxplot(aes(year, hum_satdem, group = year),
               data = DB_vdem_lib_dem,
               outlier.color="grey",
               color="grey",
               varwidth = TRUE) +
  geom_line(aes(year, hum_satdem, group = country_name, linetype = country_name), 
            data = DB_vdem_lib_dem_subgroup) +  
  scale_x_continuous(breaks=c(1995,2000, 2005, 2010, 2015, 2020),
                     limits=c(1995.5, 2018),
                     name = NULL) +
  scale_y_continuous(name="Satisfaction with democracy (HUMAN)") +
  scale_linetype_manual(values=c("dotdash", "solid")) +
  theme(legend.position="bottom",legend.text=element_text(size=7),
        legend.title = element_blank()) +
  theme_bw() + theme(panel.border = element_blank(),
                     axis.line = element_line(colour = "grey"))

# Main text figure
Figure_7 <- ggarrange(ggarrange(dim7_db_iss, dim7_cpp_ple, dim7_hum_dsa, 
                                ncol = 3, legend = "none"),nrow = 1)

# CPP
dim7_cpp_ple_eu <- ggplot() +
  geom_boxplot(aes(year, fulfil2, group = year),
               data = DB_vdem_lib_dem_EU,
               outlier.color="grey",
               color="grey",
               varwidth = TRUE) +
  geom_line(aes(year, fulfil2, group = country_name, linetype = country_name), 
            data = DB_vdem_lib_dem_EU_subgroup) +  
  scale_x_continuous(breaks=c(1995,2000, 2005, 2010, 2015, 2020),
                     name = NULL) +
  scale_y_continuous(name="Party pledge fulfillment (CPP)") +
  scale_linetype_manual(values=c("dotdash", "solid")) +
  theme(legend.position="bottom",legend.text=element_text(size=7),
        legend.title = element_blank()) +
  theme_bw() + theme(panel.border = element_blank(),
                     axis.line = element_line(colour = "grey"))

# DB
dim7_db_iss_eu <- ggplot() +
  geom_boxplot(aes(year, Issuecongr, group = year),
               data = DB_vdem_lib_dem_EU,
               outlier.color="grey",
               color="grey",
               varwidth = TRUE) +
  geom_line(aes(year, Issuecongr, group = country_name, linetype = country_name), 
            data = DB_vdem_lib_dem_EU_subgroup) +  
  scale_x_continuous(breaks=c(1995,2000, 2005, 2010, 2015, 2020),
                     limits=c(1995.5, 2018),
                     name = NULL) +
  scale_y_continuous(name="Left-right issue congruence (DB)") +
  scale_linetype_manual(values=c("dotdash", "solid")) +
  theme(legend.position="bottom",legend.text=element_text(size=7),
        legend.title = element_blank()) +
  theme_bw() + theme(panel.border = element_blank(),
                     axis.line = element_line(colour = "grey"))

# HUMAN
dim7_hum_dsa_eu <- ggplot() +
  geom_boxplot(aes(year, hum_satdem, group = year),
               data = DB_vdem_lib_dem_EU,
               outlier.color="grey",
               color="grey",
               varwidth = TRUE) +
  geom_line(aes(year, hum_satdem, group = country_name, linetype = country_name), 
            data = DB_vdem_lib_dem_EU_subgroup) +  
  scale_x_continuous(breaks=c(1995,2000, 2005, 2010, 2015, 2020),
                     limits=c(1995.5, 2018),
                     name = NULL) +
  scale_y_continuous(name="Satisfaction with democracy (HUMAN)") +
  scale_linetype_manual(values=c("dotdash", "solid")) +
  theme(legend.position="bottom",legend.text=element_text(size=7),
        legend.title = element_blank()) +
  theme_bw() + theme(panel.border = element_blank(),
                     axis.line = element_line(colour = "grey"))

# Appendix (EU countries)
Figure_A22 <- ggarrange(ggarrange(dim7_db_iss_eu, dim7_cpp_ple_eu, dim7_hum_dsa_eu, 
                                  ncol = 3, legend = "none"), nrow = 1)

# DB
dim7_db_conf <- ggplot() +
  geom_boxplot(aes(year, Confgov, group = year),
               data = DB_vdem_lib_dem,
               outlier.color="grey",
               color="grey",
               varwidth = TRUE) +
  geom_line(aes(year, Confgov, group = country_name, linetype = country_name), 
            data = DB_vdem_lib_dem_subgroup) +  
  scale_x_continuous(breaks=c(2000, 2005, 2010, 2015, 2020),
                     limits=c(1995.5, 2018),
                     name = NULL) +
  scale_y_continuous(name="Confidence in government (DB)") +
  scale_linetype_manual(values=c("dotdash", "solid")) +
  theme(legend.position="bottom",legend.text=element_text(size=7),
        legend.title = element_blank()) +
  theme_bw() + theme(panel.border = element_blank(),
                     axis.line = element_line(colour = "grey"))

# Appendix (alternative measures)
Figure_A23 <- ggarrange(ggarrange(dim7_db_conf, legend = "none"), nrow = 1)

# All plots
Figure_7
Figure_A23
Figure_A22

###==== Party organization =====

data_party_org_regressions <- read_xlsx("data_party_org_regressions.xlsx")

DB_vdem_lib_dem_vparty_subgroup <- data_party_org_regressions %>%
  filter(country_name%in%c("Italy","average_lib_dem"))

DB_vdem_lib_dem_vparty_subgroup <- DB_vdem_lib_dem_vparty_subgroup %>%
  fill(v2paind_m:pi_z)

# V-Party
dim8_vpar_per <- ggplot() +
  geom_boxplot(aes(year, v2paind_w, group = year),
               data = data_party_org_regressions,
               outlier.color="grey",
               color="grey",
               varwidth = TRUE) +
  geom_line(aes(year, v2paind_w, group = country_name, linetype = country_name), 
            data = DB_vdem_lib_dem_vparty_subgroup) +  
  scale_x_continuous(breaks=c(1995,2000, 2005, 2010, 2015, 2020),
                     limits = c(1993.5, 2020.5),
                     name = NULL) +
  scale_y_continuous(name="Party personalization (V-Party)") +
  scale_linetype_manual(values=c("dotdash", "solid")) +
  theme(legend.position="bottom",legend.text=element_text(size=7),
        legend.title = element_blank()) +
  theme_bw() + theme(panel.border = element_blank(),
                     axis.line = element_line(colour = "grey"))

# PSGO
dim8_psgo_ins <- ggplot() +
  geom_boxplot(aes(year, pi_z, group = year),
               data = data_party_org_regressions,
               outlier.color="grey",
               color="grey",
               varwidth = TRUE) +
  geom_line(aes(year, pi_z, group = country_name, linetype = country_name), 
            data = DB_vdem_lib_dem_vparty_subgroup) +  
  scale_x_continuous(breaks=c(1995,2000, 2005, 2010, 2015, 2020),
                     limits = c(1993.5, 2021),
                     name = NULL) +
  scale_y_continuous(name="Party institutionalization (PSGO)") +
  scale_linetype_manual(values=c("dotdash", "solid")) +
  theme(legend.position="bottom",legend.text=element_text(size=7),
        legend.title = element_blank()) +
  theme_bw() + theme(panel.border = element_blank(),
                     axis.line = element_line(colour = "grey"))

Figure_8 <- ggarrange(ggarrange(dim8_vpar_per, dim8_psgo_ins, ncol = 2, 
                                           nrow = 1, legend = "none"))
Figure_8

#==== Multi-level graphs and regressions =====

# Fill missings for non-electoral years
data_party_org_regressions_imp <- data_party_org_regressions %>%
  group_by(country_name) %>%
  fill(v2paind_m:pi_z)

summary(data_party_org_regressions_imp$v2paind_l)
summary(data_party_org_regressions_imp$pi_z_l)
summary(data_party_org_regressions_imp$e_gdp_ll) 
summary(data_party_org_regressions_imp$e_gdppc_ll) 
summary(data_party_org_regressions_imp$e_wb_pop_ll)

# exclude average
data_party_org_regressions_imp <- data_party_org_regressions_imp %>%
  filter(
    country_name != "average_lib_dem")

## Multi-level graphs
Figure_A27 <- ggplot(data_party_org_regressions_imp, aes(x=v2paind_l, y = v2x_rule)) +
  geom_point(aes(colour=country_name)) +
  geom_smooth(method = "lm", se = FALSE, size = 2, colour= "black") +
  geom_smooth(method = "lm", aes(colour=country_name), se=FALSE) +
  scale_x_continuous(name="Party personalization (V-Party)") +
  scale_y_continuous(name="Rule of law (V-Dem)") +
  theme_classic() +
  theme(legend.position="bottom", legend.title = element_blank())

Figure_A28 <- ggplot(data_party_org_regressions_imp, aes(x=v2paind_l, y = v2x_rule)) +
  geom_point(aes(colour=country_name)) +
  geom_smooth(method = "lm", se = FALSE) +
  geom_smooth(method = "lm", aes(colour=country_name), se=FALSE) +
  gghighlight(country_name == "Italy", label_key = country_name) +
  theme_classic() +
  scale_x_continuous(name="Party personalization (V-Party)") +
  scale_y_continuous(name="Rule of law (V-Dem)") +
  theme_classic() +
  theme(legend.position="bottom", legend.title = element_blank())

Figure_A29 <- ggplot(data_party_org_regressions_imp, aes(x=pi_z_l, y = v2x_rule)) +
  geom_point(aes(colour=country_name)) +
  geom_smooth(method = "lm", se = FALSE, size = 2, colour= "black") +
  geom_smooth(method = "lm", aes(colour=country_name), se=FALSE) +
  scale_x_continuous(name="Party institutionalization (PSGO)") +
  scale_y_continuous(name="Rule of law (V-Dem)") +
  theme_classic() +
  theme(legend.position="bottom", legend.title = element_blank())

Figure_A30 <- ggplot(data_party_org_regressions_imp, aes(x=pi_z_l, y = v2x_rule)) +
  geom_point(aes(colour=country_name)) +
  geom_smooth(method = "lm", se = FALSE) +
  geom_smooth(method = "lm", aes(colour=country_name), se=FALSE) +
  gghighlight(country_name == "Italy", label_key = country_name) +
  theme_classic() +
  scale_x_continuous(name="Party institutionalization (PSGO)") +
  scale_y_continuous(name="Rule of law (V-Dem)") +
  theme_classic() +
  theme(legend.position="bottom", legend.title = element_blank())

Figure_A25 <- ggplot(data_party_org_regressions_imp, aes(x=v2paind_l, y = pi_z_l)) +
  geom_point(aes(colour=country_name)) +
  geom_smooth(method = "lm", se = FALSE, size = 2, colour= "black") +
  geom_smooth(method = "lm", aes(colour=country_name), se=FALSE) +
  scale_y_continuous(name="Party institutionalization (PSGO)") +
  scale_x_continuous(name="Party personalization (V-Dem)") +
  theme_classic() +
  theme(legend.position="bottom", legend.title = element_blank())

Figure_A26 <- ggplot(data_party_org_regressions_imp, aes(x=v2paind_l, y = pi_z_l)) +
  geom_point(aes(colour=country_name)) +
  geom_smooth(method = "lm", se = FALSE) +
  geom_smooth(method = "lm", aes(colour=country_name), se=FALSE) +
  gghighlight(country_name == "Italy", label_key = country_name) +
  theme_classic() +
  scale_y_continuous(name="Party institutionalization (PSGO)") +
  scale_x_continuous(name="Party personalization (V-Dem)") +
  theme_classic() +
  theme(legend.position="bottom", legend.title = element_blank())

# See all the graphs at the end of the graphs section

data_party_org_regressions_imp <- 
  pdata.frame(data_party_org_regressions_imp,
              index = c("country_name", "year"))

# Again re-scale between 0 and 1
data_party_org_regressions_imp <- data_party_org_regressions_imp %>%
  mutate(
    RULEOFLAW = RULEOFLAW/5,
    TRANSPAR = TRANSPAR/5,
    RL_QUAL3 = RL_QUAL3/6,
    Rule.of.Law = Rule.of.Law/10,
    wbgi_rle = wbgi_rle/2.3,
    fh_rol = fh_rol/18,
    wbgi_vae = wbgi_vae/2,
    v2x_accountability = v2x_accountability/2.3,
    v2x_diagacc = v2x_diagacc/2.3,
    MUTUCONS = MUTUCONS/5,
    wbgi_vae = wbgi_vae/2,
    Executive.Accountability = Executive.Accountability/10,
    Legislative.Actors..Resources = Legislative.Actors..Resources/10,
    Independent.Supervisory.Bodies = Independent.Supervisory.Bodies/10,
    v2cagenmob = (v2cagenmob+2.6720)/6.5,
    PAR_EFPA = PAR_EFPA/5,
    turnout = turnout/100,
    van_part = van_part/100,
    ideavt_euvt = ideavt_euvt/100,
    fh_ppp = fh_ppp/18,
    COMPET = COMPET/5,
    closure_c = closure_c/100,
    enep = enep/11,
    volatility = volatility/40,
    van_comp = van_comp/100,
    evep_tv = evep_tv/55,
    psi_psi1 = psi_psi1/37,
    v2cltort = v2cltort/4,
    v2clkill = v2clkill/5,
    v2clslavef = v2clslavef/4,
    v2clacfree = v2clacfree/5,
    v2clstown = v2clstown/4,
    v2cltort = v2cltort/4,
    fhp_score5 = fhp_score5/55,
    fh_feb = fh_feb/18,
    Civil.Rights.and.Political.Liberties = Civil.Rights.and.Political.Liberties/10,
    e_peaveduc = e_peaveduc/15,
    v2pehealth = v2pehealth/4,
    v2elsnlsff = v2elsnlsff/4,
    Social.Inclusion = Social.Inclusion/10,
    `Health` = `Health`/10,
    Confgov = Confgov/7,
    Issuecongr = Issuecongr/8,
    hum_satdem = hum_satdem/100
  )

# Baseline models
mod_dim1_A_i <- feols(v2x_rule ~ pi_z_l + e_gdppc_ll + e_wb_pop_ll | year, 
                      cluster = "country_name", data = data_party_org_regressions_imp)
mod_dim1_A_p <- feols(v2x_rule ~ v2paind_l + e_gdppc_ll + e_wb_pop_ll | year, 
                      cluster = "country_name", data = data_party_org_regressions_imp)
mod_dim1_B_i <- feols(RULEOFLAW  ~ pi_z_l + e_gdppc_ll + e_wb_pop_ll | year, 
                      cluster = "country_name", data = data_party_org_regressions_imp)
mod_dim1_B_p <- feols(RULEOFLAW  ~ v2paind_l + e_gdppc_ll + e_wb_pop_ll | year, 
                      cluster = "country_name", data = data_party_org_regressions_imp)
mod_dim1_C_i <- feols(wbgi_rle ~ pi_z_l + e_gdppc_ll + e_wb_pop_ll | year, 
                      cluster = "country_name", data = data_party_org_regressions_imp)
mod_dim1_C_p <- feols(wbgi_rle ~ v2paind_l + e_gdppc_ll + e_wb_pop_ll | year, 
                      cluster = "country_name", data = data_party_org_regressions_imp)
mod_dim2_A_i <- feols(v2x_accountability    ~ pi_z_l + e_gdppc_ll + e_wb_pop_ll | year, 
                      cluster = "country_name", data = data_party_org_regressions_imp)
mod_dim2_A_p <- feols(v2x_accountability    ~ v2paind_l + e_gdppc_ll + e_wb_pop_ll | year, 
                      cluster = "country_name", data = data_party_org_regressions_imp)
mod_dim2_B_i <- feols(MUTUCONS    ~ pi_z_l + e_gdppc_ll + e_wb_pop_ll | year, 
                      cluster = "country_name", data = data_party_org_regressions_imp)
mod_dim2_B_p <- feols(MUTUCONS    ~ v2paind_l + e_gdppc_ll + e_wb_pop_ll | year, 
                      cluster = "country_name", data = data_party_org_regressions_imp)
mod_dim2_C_i <- feols(wbgi_vae ~ pi_z_l + e_gdppc_ll + e_wb_pop_ll | year, 
                      cluster = "country_name", data = data_party_org_regressions_imp)
mod_dim2_C_p <- feols(wbgi_vae ~ v2paind_l + e_gdppc_ll + e_wb_pop_ll | year, 
                      cluster = "country_name", data = data_party_org_regressions_imp)
mod_dim3_A_i <- feols(v2x_partip    ~ pi_z_l + e_gdppc_ll + e_wb_pop_ll | year, 
                      cluster = "country_name", data = data_party_org_regressions_imp)
mod_dim3_A_p <- feols(v2x_partip    ~ v2paind_l + e_gdppc_ll + e_wb_pop_ll | year, 
                      cluster = "country_name", data = data_party_org_regressions_imp)
mod_dim3_B_i <- feols(PAR_EFPA ~ pi_z_l + e_gdppc_ll + e_wb_pop_ll | year, 
                      cluster = "country_name", data = data_party_org_regressions_imp)
mod_dim3_B_p <- feols(PAR_EFPA ~ v2paind_l + e_gdppc_ll + e_wb_pop_ll | year, 
                      cluster = "country_name", data = data_party_org_regressions_imp)
mod_dim3_C_i <- feols(fh_ppp ~ pi_z_l + e_gdppc_ll + e_wb_pop_ll | year, 
                      cluster = "country_name", data = data_party_org_regressions_imp)
mod_dim3_C_p <- feols(fh_ppp ~ v2paind_l + e_gdppc_ll + e_wb_pop_ll | year, 
                      cluster = "country_name", data = data_party_org_regressions_imp)
mod_dim4_A_i <- feols(closure_c ~ pi_z_l + e_gdppc_ll + e_wb_pop_ll | year, 
                      cluster = "country_name", data = data_party_org_regressions_imp)
mod_dim4_A_p <- feols(closure_c ~ v2paind_l + e_gdppc_ll + e_wb_pop_ll | year, 
                      cluster = "country_name", data = data_party_org_regressions_imp)
mod_dim4_B_i <- feols(volatility ~ pi_z_l + e_gdppc_ll + e_wb_pop_ll | year, 
                      cluster = "country_name", data = data_party_org_regressions_imp)
mod_dim4_B_p <- feols(volatility ~ v2paind_l + e_gdppc_ll + e_wb_pop_ll | year, 
                      cluster = "country_name", data = data_party_org_regressions_imp)
mod_dim4_C_i <- feols(psi_psi1 ~ pi_z_l + e_gdppc_ll + e_wb_pop_ll | year, 
                      cluster = "country_name", data = data_party_org_regressions_imp)
mod_dim4_C_p <- feols(psi_psi1 ~ v2paind_l + e_gdppc_ll + e_wb_pop_ll | year, 
                      cluster = "country_name", data = data_party_org_regressions_imp)
mod_dim5_A_i <- feols(v2clkill ~ pi_z_l + e_gdppc_ll + e_wb_pop_ll | year, 
                      cluster = "country_name", data = data_party_org_regressions_imp)
mod_dim5_A_p <- feols(v2clkill ~ v2paind_l + e_gdppc_ll + e_wb_pop_ll | year, 
                      cluster = "country_name", data = data_party_org_regressions_imp)
mod_dim5_B_i <- feols(v2clslavef ~ pi_z_l + e_gdppc_ll + e_wb_pop_ll | year, 
                      cluster = "country_name", data = data_party_org_regressions_imp)
mod_dim5_B_p <- feols(v2clslavef ~ v2paind_l + e_gdppc_ll + e_wb_pop_ll | year, 
                      cluster = "country_name", data = data_party_org_regressions_imp)
mod_dim5_C_i <- feols(v2clacfree ~ pi_z_l + e_gdppc_ll + e_wb_pop_ll | year, 
                      cluster = "country_name", data = data_party_org_regressions_imp)
mod_dim5_C_p <- feols(v2clacfree ~ v2paind_l + e_gdppc_ll + e_wb_pop_ll | year, 
                      cluster = "country_name", data = data_party_org_regressions_imp)
mod_dim6_A_i <- feols(e_peaveduc ~ pi_z_l + e_gdppc_ll + e_wb_pop_ll | year, 
                      cluster = "country_name", data = data_party_org_regressions_imp)
mod_dim6_A_p <- feols(e_peaveduc ~ v2paind_l + e_gdppc_ll + e_wb_pop_ll | year, 
                      cluster = "country_name", data = data_party_org_regressions_imp)
mod_dim6_B_i <- feols(income_gini  ~ pi_z_l + e_gdppc_ll + e_wb_pop_ll | year, 
                      cluster = "country_name", data = data_party_org_regressions_imp)
mod_dim6_B_p <- feols(income_gini  ~ v2paind_l + e_gdppc_ll + e_wb_pop_ll | year, 
                      cluster = "country_name", data = data_party_org_regressions_imp)
mod_dim6_C_i <- feols(v2elsnlsff   ~ pi_z_l + e_gdppc_ll + e_wb_pop_ll | year, 
                      cluster = "country_name", data = data_party_org_regressions_imp)
mod_dim6_C_p <- feols(v2elsnlsff   ~ v2paind_l + e_gdppc_ll + e_wb_pop_ll | year, 
                      cluster = "country_name", data = data_party_org_regressions_imp)
mod_dim7_A_i <- feols(Issuecongr   ~ pi_z_l + e_gdppc_ll + e_wb_pop_ll | year, 
                      cluster = "country_name", data = data_party_org_regressions_imp)
mod_dim7_A_p <- feols(Issuecongr   ~ v2paind_l + e_gdppc_ll + e_wb_pop_ll | year, 
                      cluster = "country_name", data = data_party_org_regressions_imp)
mod_dim7_B_i <- feols(fulfil2   ~ pi_z_l + e_gdppc_ll + e_wb_pop_ll | year, 
                      cluster = "country_name", data = data_party_org_regressions_imp)
mod_dim7_B_p <- feols(fulfil2   ~ v2paind_l + e_gdppc_ll + e_wb_pop_ll | year, 
                      cluster = "country_name", data = data_party_org_regressions_imp)
mod_dim7_C_i <- feols(hum_satdem ~ pi_z_l + e_gdppc_ll + e_wb_pop_ll | year, 
                      cluster = "country_name", data = data_party_org_regressions_imp)
mod_dim7_C_p <- feols(hum_satdem ~ v2paind_l + e_gdppc_ll + e_wb_pop_ll | year, 
                      cluster = "country_name", data = data_party_org_regressions_imp)

# Appendix models
modapp_dim1_A_i <- feols(Rule.of.Law ~ pi_z_l + e_gdppc_ll + e_wb_pop_ll | year, 
                         cluster = "country_name", data = data_party_org_regressions_imp)
modapp_dim1_A_p <- feols(Rule.of.Law ~ v2paind_l + e_gdppc_ll + e_wb_pop_ll | year, 
                         cluster = "country_name", data = data_party_org_regressions_imp)
modapp_dim1_B_i <- feols(wjp_overall ~ pi_z_l + e_gdppc_ll + e_wb_pop_ll | year, 
                         cluster = "country_name", data = data_party_org_regressions_imp)
modapp_dim1_B_p <- feols(wjp_overall ~ v2paind_l + e_gdppc_ll + e_wb_pop_ll | year, 
                         cluster = "country_name", data = data_party_org_regressions_imp)
modapp_dim1_C_i <- feols(fh_rol ~ pi_z_l + e_gdppc_ll + e_wb_pop_ll | year, 
                         cluster = "country_name", data = data_party_org_regressions_imp)
modapp_dim1_C_p <- feols(fh_rol ~ v2paind_l + e_gdppc_ll + e_wb_pop_ll | year, 
                         cluster = "country_name", data = data_party_org_regressions_imp)
modapp_dim1_D_i <- feols(TRANSPAR   ~ pi_z_l + e_gdppc_ll + e_wb_pop_ll | year, 
                         cluster = "country_name", data = data_party_org_regressions_imp)
modapp_dim1_D_p <- feols(TRANSPAR   ~ v2paind_l + e_gdppc_ll + e_wb_pop_ll | year, 
                         cluster = "country_name", data = data_party_org_regressions_imp)
modapp_dim1_E_i <- feols(RL_QUAL3   ~ pi_z_l + e_gdppc_ll + e_wb_pop_ll | year, 
                         cluster = "country_name", data = data_party_org_regressions_imp)
modapp_dim1_E_p <- feols(RL_QUAL3   ~ v2paind_l + e_gdppc_ll + e_wb_pop_ll | year, 
                         cluster = "country_name", data = data_party_org_regressions_imp)
modapp_dim2_A_i <- feols(Executive.Accountability ~ pi_z_l + e_gdppc_ll + e_wb_pop_ll | year, 
                         cluster = "country_name", data = data_party_org_regressions_imp)
modapp_dim2_A_p <- feols(Executive.Accountability ~ v2paind_l + e_gdppc_ll + e_wb_pop_ll | year, 
                         cluster = "country_name", data = data_party_org_regressions_imp)
modapp_dim2_B_i <- feols(Independent.Supervisory.Bodies ~ pi_z_l + e_gdppc_ll + e_wb_pop_ll | year, 
                         cluster = "country_name", data = data_party_org_regressions_imp)
modapp_dim2_B_p <- feols(Independent.Supervisory.Bodies ~ v2paind_l + e_gdppc_ll + e_wb_pop_ll | year, 
                         cluster = "country_name", data = data_party_org_regressions_imp)
modapp_dim2_C_i <- feols(electoral_reforms    ~ pi_z_l + e_gdppc_ll + e_wb_pop_ll | year, 
                         cluster = "country_name", data = data_party_org_regressions_imp)
modapp_dim2_C_p <- feols(electoral_reforms    ~ v2paind_l + e_gdppc_ll + e_wb_pop_ll | year, 
                         cluster = "country_name", data = data_party_org_regressions_imp)
modapp_dim2_D_i <- feols(v2x_diagacc    ~ pi_z_l + e_gdppc_ll + e_wb_pop_ll | year, 
                         cluster = "country_name", data = data_party_org_regressions_imp)
modapp_dim2_D_p <- feols(v2x_diagacc    ~ v2paind_l + e_gdppc_ll + e_wb_pop_ll | year, 
                         cluster = "country_name", data = data_party_org_regressions_imp)
modapp_dim3_A_i <- feols(v2cagenmob    ~ pi_z_l + e_gdppc_ll + e_wb_pop_ll | year, 
                         cluster = "country_name", data = data_party_org_regressions_imp)
modapp_dim3_A_p <- feols(v2cagenmob    ~ v2paind_l + e_gdppc_ll + e_wb_pop_ll | year, 
                         cluster = "country_name", data = data_party_org_regressions_imp)
modapp_dim3_B_i <- feols(van_part ~ pi_z_l + e_gdppc_ll + e_wb_pop_ll | year, 
                         cluster = "country_name", data = data_party_org_regressions_imp)
modapp_dim3_B_p <- feols(van_part ~ v2paind_l + e_gdppc_ll + e_wb_pop_ll | year, 
                         cluster = "country_name", data = data_party_org_regressions_imp)
modapp_dim3_C_i <- feols(turnout ~ pi_z_l + e_gdppc_ll + e_wb_pop_ll | year, 
                         cluster = "country_name", data = data_party_org_regressions_imp)
modapp_dim3_C_p <- feols(turnout ~ v2paind_l + e_gdppc_ll + e_wb_pop_ll | year, 
                         cluster = "country_name", data = data_party_org_regressions_imp)
modapp_dim3_D_i <- feols(ideavt_euvt ~ pi_z_l + e_gdppc_ll + e_wb_pop_ll | year, 
                         cluster = "country_name", data = data_party_org_regressions_imp)
modapp_dim3_D_p <- feols(ideavt_euvt ~ v2paind_l + e_gdppc_ll + e_wb_pop_ll | year, 
                         cluster = "country_name", data = data_party_org_regressions_imp)
modapp_dim4_A_i <- feols(COMPET ~ pi_z_l + e_gdppc_ll + e_wb_pop_ll | year, 
                         cluster = "country_name", data = data_party_org_regressions_imp)
modapp_dim4_A_p <- feols(COMPET ~ v2paind_l + e_gdppc_ll + e_wb_pop_ll | year, 
                         cluster = "country_name", data = data_party_org_regressions_imp)
modapp_dim4_B_i <- feols(van_comp ~ pi_z_l + e_gdppc_ll + e_wb_pop_ll | year, 
                         cluster = "country_name", data = data_party_org_regressions_imp)
modapp_dim4_B_p <- feols(van_comp ~ v2paind_l + e_gdppc_ll + e_wb_pop_ll | year, 
                         cluster = "country_name", data = data_party_org_regressions_imp)
modapp_dim4_C_i <- feols(enep ~ pi_z_l + e_gdppc_ll + e_wb_pop_ll | year, 
                         cluster = "country_name", data = data_party_org_regressions_imp)
modapp_dim4_C_p <- feols(enep ~ v2paind_l + e_gdppc_ll + e_wb_pop_ll | year, 
                         cluster = "country_name", data = data_party_org_regressions_imp)
modapp_dim4_D_i <- feols(cpds_frel ~ pi_z_l + e_gdppc_ll + e_wb_pop_ll | year, 
                         cluster = "country_name", data = data_party_org_regressions_imp)
modapp_dim4_D_p <- feols(cpds_frel ~ v2paind_l + e_gdppc_ll + e_wb_pop_ll | year, 
                         cluster = "country_name", data = data_party_org_regressions_imp)
modapp_dim4_E_i <- feols(evep_tv ~ pi_z_l + e_gdppc_ll + e_wb_pop_ll | year, 
                         cluster = "country_name", data = data_party_org_regressions_imp)
modapp_dim4_E_p <- feols(evep_tv ~ v2paind_l + e_gdppc_ll + e_wb_pop_ll | year, 
                         cluster = "country_name", data = data_party_org_regressions_imp)
modapp_dim5_A_i <- feols(v2cltort ~ pi_z_l + e_gdppc_ll + e_wb_pop_ll | year, 
                         cluster = "country_name", data = data_party_org_regressions_imp)
modapp_dim5_A_p <- feols(v2cltort ~ v2paind_l + e_gdppc_ll + e_wb_pop_ll | year, 
                         cluster = "country_name", data = data_party_org_regressions_imp)
modapp_dim5_B_i <- feols(v2clstown ~ pi_z_l + e_gdppc_ll + e_wb_pop_ll | year, 
                         cluster = "country_name", data = data_party_org_regressions_imp)
modapp_dim5_B_p <- feols(v2clstown ~ v2paind_l + e_gdppc_ll + e_wb_pop_ll | year, 
                         cluster = "country_name", data = data_party_org_regressions_imp)
modapp_dim5_C_i <- feols(fhp_score5 ~ pi_z_l + e_gdppc_ll + e_wb_pop_ll | year, 
                         cluster = "country_name", data = data_party_org_regressions_imp)
modapp_dim5_C_p <- feols(fhp_score5 ~ v2paind_l + e_gdppc_ll + e_wb_pop_ll | year, 
                         cluster = "country_name", data = data_party_org_regressions_imp)
modapp_dim5_D_i <- feols(fh_feb ~ pi_z_l + e_gdppc_ll + e_wb_pop_ll | year, 
                         cluster = "country_name", data = data_party_org_regressions_imp)
modapp_dim5_D_p <- feols(fh_feb ~ v2paind_l + e_gdppc_ll + e_wb_pop_ll | year, 
                         cluster = "country_name", data = data_party_org_regressions_imp)
modapp_dim5_E_i <- feols(Civil.Rights.and.Political.Liberties ~ pi_z_l + e_gdppc_ll + e_wb_pop_ll | year, 
                         cluster = "country_name", data = data_party_org_regressions_imp)
modapp_dim5_E_p <- feols(Civil.Rights.and.Political.Liberties ~ v2paind_l + e_gdppc_ll + e_wb_pop_ll | year, 
                         cluster = "country_name", data = data_party_org_regressions_imp)
modapp_dim6_A_i <- feols(v2pehealth   ~ pi_z_l + e_gdppc_ll + e_wb_pop_ll | year, 
                         cluster = "country_name", data = data_party_org_regressions_imp)
modapp_dim6_A_p <- feols(v2pehealth   ~ v2paind_l + e_gdppc_ll + e_wb_pop_ll | year, 
                         cluster = "country_name", data = data_party_org_regressions_imp)
modapp_dim6_B_i <- feols(gii_gii ~ pi_z_l + e_gdppc_ll + e_wb_pop_ll | year, 
                         cluster = "country_name", data = data_party_org_regressions_imp)
modapp_dim6_B_p <- feols(gii_gii ~ v2paind_l + e_gdppc_ll + e_wb_pop_ll | year, 
                         cluster = "country_name", data = data_party_org_regressions_imp)
modapp_dim6_C_i <- feols(oecd_incinequal_t1a ~ pi_z_l + e_gdppc_ll + e_wb_pop_ll | year, 
                         cluster = "country_name", data = data_party_org_regressions_imp)
modapp_dim6_C_p <- feols(oecd_incinequal_t1a ~ v2paind_l + e_gdppc_ll + e_wb_pop_ll | year, 
                         cluster = "country_name", data = data_party_org_regressions_imp)
modapp_dim6_D_i <- feols(Social.Inclusion ~ pi_z_l + e_gdppc_ll + e_wb_pop_ll | year, 
                         cluster = "country_name", data = data_party_org_regressions_imp)
modapp_dim6_D_p <- feols(Social.Inclusion ~ v2paind_l + e_gdppc_ll + e_wb_pop_ll | year, 
                         cluster = "country_name", data = data_party_org_regressions_imp)
modapp_dim6_E_i <- feols(Health ~ pi_z_l + e_gdppc_ll + e_wb_pop_ll | year, 
                         cluster = "country_name", data = data_party_org_regressions_imp)
modapp_dim6_E_p <- feols(Health ~ v2paind_l + e_gdppc_ll + e_wb_pop_ll | year, 
                         cluster = "country_name", data = data_party_org_regressions_imp)
modapp_dim7_A_i <- feols(Confgov   ~ pi_z_l + e_gdppc_ll + e_wb_pop_ll | year, 
                         cluster = "country_name", data = data_party_org_regressions_imp)
modapp_dim7_A_p <- feols(Confgov   ~ v2paind_l + e_gdppc_ll + e_wb_pop_ll | year, 
                         cluster = "country_name", data = data_party_org_regressions_imp)

##==== Graphs =====
# Baseline models
models <- list(
  "7. Satisfaction with democracy (HUMAN)" = mod_dim7_C_p,
  "7. Satisfaction with democracy (HUMAN)" = mod_dim7_C_i,
  "7. Party pledge fulfillment (CPP)" = mod_dim7_B_p,
  "7. Party pledge fulfillment (CPP)" = mod_dim7_B_i,
  "7. Left-right issue congruence (DB)" = mod_dim7_A_i,
  "7. Left-right issue congruence (DB)" = mod_dim7_A_p, 
  "6. Subnational election eveness (V-Dem)" = mod_dim6_C_p,
  "6. Subnational election eveness (V-Dem)" = mod_dim6_C_i, 
  "6. Income gini (LIS)" = mod_dim6_B_i,
  "6. Income gini (LIS)" =  mod_dim6_B_p, 
  "6. Education 15+ (CLIO)" = mod_dim6_A_i,
  "6. Education 15+ (CLIO)" = mod_dim6_A_p, 
  "5. Freedom of academic discussion (V-Dem)" = mod_dim5_C_i,
  "5. Freedom of academic discussion (V-Dem)" = mod_dim5_C_p, 
  "5. Freedom from forced labor for women (V-Dem)" = mod_dim5_B_i,
  "5. Freedom from forced labor for women (V-Dem)" = mod_dim5_B_p,
  "5. Freedom from political killings (V-Dem)" = mod_dim5_A_i,
  "5. Freedom from political killings (V-Dem)" = mod_dim5_A_p,  
  "4. Party system innovation (DEV)" = mod_dim4_C_i,
  "4. Party system innovation (DEV)" = mod_dim4_C_p,
  "4. Volatility (DEV)" = mod_dim4_B_i,
  "4. Volatility (DEV)" = mod_dim4_B_p, 
  "4. Party system closure (PSGO)" = mod_dim4_A_p, 
  "4. Party system closure (PSGO)" = mod_dim4_A_i,
  "3. Political pluralism and participation (FH)" = mod_dim3_C_i,
  "3. Political pluralism and participation (FH)" = mod_dim3_C_p, 
  "3. Effective participation (DB)" = mod_dim3_B_i,
  "3. Effective participation (DB)" = mod_dim3_B_p, 
  "3. Participation (V-Dem)" = mod_dim3_A_i, 
  "3. Participation (V-Dem)" = mod_dim3_A_p,
  "2. Accountability (WB)" = mod_dim2_C_i,
  "2. Accountability (WB)" = mod_dim2_C_p, 
  "2. Mutual constraints of executive power (DB)" = mod_dim2_B_i,
  "2. Mutual constraints of executive power (DB)" = mod_dim2_B_p, 
  "2. Accountability (V-Dem)" = mod_dim2_A_i,
  "2. Accountability (V-Dem)" = mod_dim2_A_p, 
  "1. Rule of Law (WB)" = mod_dim1_C_i,
  "1. Rule of Law (WB)" = mod_dim1_C_p, 
  "1. Rule of Law (DB)" = mod_dim1_B_i,
  "1. Rule of Law (DB)" = mod_dim1_B_p, 
  "1. Rule of Law (V-Dem)" = mod_dim1_A_i,
  "1. Rule of Law (V-Dem)" = mod_dim1_A_p)

cm <- c('v2paind_l'    = 'Party personalization',
        "pi_z_l" = "Party institutionalization")
plot_model_paper <- modelsummary::modelplot(models, 
                                            coef_map = cm,
                                            conf_level = .9,
                                            facet = TRUE) + 
  aes(color = ifelse(p.value < 0.1, "Significant", "Not significant")) +
  scale_color_manual(values = c("grey", "black")) + theme(legend.position="bottom")

Figure_9 <- plot_model_paper + geom_vline(xintercept = 0, color = "grey", size=0.5)
Figure_9

# Appendix models
models_appendix <- list("7. Confidence in government (DB)" = modapp_dim7_A_p,
                        "7. Confidence in government (DB)" = modapp_dim7_A_i,
                        "6. Health (BTI)" = modapp_dim6_E_p,
                        "6. Health (BTI)" = modapp_dim6_E_i,
                        "6. Social inclusion (BTI)" = modapp_dim6_D_p,
                        "6. Social inclusion (BTI)" = modapp_dim6_D_i,
                        "6. Income gini (CSP)" = modapp_dim6_C_p,
                        "6. Income gini (CSP)" = modapp_dim6_C_i,
                        "6. Gender inequality index (UN)" = modapp_dim6_B_p,
                        "6. Gender inequality index (UN)" = modapp_dim6_B_i,
                        "6. Health inequality (V-Dem)" = modapp_dim6_A_p,
                        "6. Health inequality (V-Dem)" = modapp_dim6_A_i,
                        "5. Civil Rights and Political liberties (BTI)" = modapp_dim5_E_p,
                        "5. Civil Rights and Political liberties (BTI)" = modapp_dim5_E_i,
                        "5. Freedom of expression and belief (FH)" = modapp_dim5_D_p,
                        "5. Freedom of expression and belief (FH)" = modapp_dim5_D_i,
                        "5. Freedom of the Press (FoP)" = modapp_dim5_C_p,
                        "5. Freedom of the Press (FoP)" = modapp_dim5_C_i,
                        "5. State ownership of economy (V-Dem)" = modapp_dim5_B_p,
                        "5. State ownership of economy (V-Dem)" = modapp_dim5_B_i,
                        "5. Freedom from torture (V-Dem)" = modapp_dim5_A_p,
                        "5. Freedom from torture (V-Dem)" = modapp_dim5_A_i,
                        "4. Total volatility EP (DEV)" = modapp_dim4_E_p,
                        "4. Total volatility EP (DEV)" = modapp_dim4_E_i,
                        "4. Legislative fract. party system (Rae/CPD)" = modapp_dim4_D_p,
                        "4. Legislative fract. party system (Rae/CPD)" = modapp_dim4_D_i,
                        "4. Electoral Fragmentation (PSGO)" = modapp_dim4_C_p,
                        "4. Electoral Fragmentation (PSGO)" = modapp_dim4_C_i,
                        "4. Competition index (Vanhanen)" = modapp_dim4_B_p,
                        "4. Competition index (Vanhanen)" = modapp_dim4_B_i,
                        "4. Competition (DB)" = modapp_dim4_A_p,
                        "4. Competition (DB)" = modapp_dim4_A_i,
                        "3. Turnout EP elections (IDEA)" = modapp_dim3_D_p,
                        "3. Turnout EP elections (IDEA)" = modapp_dim3_D_i,
                        "3. Turnout (IDEA)" = modapp_dim3_C_p,
                        "3. Turnout (IDEA)" = modapp_dim3_C_i,
                        "3. Participation index (Vanhanen)" = modapp_dim3_B_p,
                        "3. Participation index (Vanhanen)" = modapp_dim3_B_i,
                        "3. Mass mobilization (V-Dem)" = modapp_dim3_A_p,
                        "3. Mass mobilization (V-Dem)" = modapp_dim3_A_i,
                        "2. Diagonal accountability (V-Dem)" = modapp_dim2_D_p,
                        "2. Diagonal accountability (V-Dem)" = modapp_dim2_D_i,
                        # "2. Electoral reforms (IDEA)" = modapp_dim2_C_p, # excluded from the graph
                        # "2. Electoral reforms (IDEA)" = modapp_dim2_C_i, # for visualization purposes
                        "2. Independent Supervisory Bodies (BTI)" = modapp_dim2_B_p,
                        "2. Independent Supervisory Bodies (BTI)" = modapp_dim2_B_i,
                        "2. Executive accountability (BTI)" = modapp_dim2_A_p,
                        "2. Executive accountability (BTI)" = modapp_dim2_A_i,
                        "1. Confidence in the police (DB)" = modapp_dim1_E_p,
                        "1. Confidence in the police (DB)"	 = modapp_dim1_E_i,
                        "1. Transparency (DB)" = modapp_dim1_D_p,
                        "1. Transparency (DB)" = modapp_dim1_D_i,
                        "1. Rule of Law (FH)" = modapp_dim1_C_p,
                        "1. Rule of Law (FH)" = modapp_dim1_C_i,
                        "1. Rule of Law (WJP)" = modapp_dim1_B_p,
                        "1. Rule of Law (WJP)" = modapp_dim1_B_i,
                        "1. Rule of Law (BTI)" = modapp_dim1_A_p,
                        "1. Rule of Law (BTI)" = modapp_dim1_A_i)

plot_model_paper_appendix <- modelsummary::modelplot(models_appendix, 
                                                     coef_map = cm,
                                                     conf_level = .9,
                                                     facet = TRUE) + 
  aes(color = ifelse(p.value < 0.05, "Significant", "Not significant")) +
  scale_color_manual(values = c("grey", "black")) + theme(legend.position="bottom")

Figure_A24 <- plot_model_paper_appendix + geom_vline(xintercept = 0, color = "grey", size=0.5)
Figure_A24

# Multi-level graphs
Figure_A25
Figure_A26
Figure_A27
Figure_A28
Figure_A29
Figure_A30

##==== Tables =====
# Baseline models
cm_table <- c('v2paind_l'    = 'Party personalization',
              "pi_z_l" = "Party institutionalization",
              "e_gdp_ll" = "GDP (log)",
              "e_gdppc_ll" = "GDP pc (log)",
              "e_wb_pop_ll" = "Population (log)")

Table_A4_models <- list(
  "1. Rule of Law (V-Dem)" = mod_dim1_A_p,
  "1. Rule of Law (V-Dem)" = mod_dim1_A_i,
  "1. Rule of Law (DB)" = mod_dim1_B_p,
  "1. Rule of Law (DB)" = mod_dim1_B_i,
  "1. Rule of Law (WB)" = mod_dim1_C_p, 
  "1. Rule of Law (WB)" = mod_dim1_C_i)

Table_A4 <- modelsummary::modelsummary(Table_A4_models, 
                                                  coef_map = cm_table,
                                                  # output = "flextable",
                                                  estimate = "{estimate}{stars} ({std.error})",
                                                  conf_level = .9,
                                                  gof_omit = 'R2 Within|R2 Within Adj.|AIC|BIC|RMSE',
                                                  statistic = NULL,
                                                  fmt = 3)
Table_A5_models <- list(
  "2. Accountability (V-Dem)" = mod_dim2_A_p, 
  "2. Accountability (V-Dem)" = mod_dim2_A_i, # 2
  "2. Mutual constraints of executive power (DB)" = mod_dim2_B_p, 
  "2. Mutual constraints of executive power (DB)" = mod_dim2_B_i,
  "2. Accountability (WB)" = mod_dim2_C_p, 
  "2. Accountability (WB)" = mod_dim2_C_i)

Table_A5 <- modelsummary::modelsummary(Table_A5_models, 
                                                  coef_map = cm_table,
                                                  # output = "flextable",
                                                  estimate = "{estimate}{stars} ({std.error})",
                                                  conf_level = .9,
                                                  gof_omit = 'R2 Within|R2 Within Adj.|AIC|BIC|RMSE',
                                                  statistic = NULL,
                                                  fmt = 3)

Table_A6_models <- list(
  "3. Participation (V-Dem)" = mod_dim3_A_p,
  "3. Participation (V-Dem)" = mod_dim3_A_i, 
  "3. Effective participation (DB)" = mod_dim3_B_p, 
  "3. Effective participation (DB)" = mod_dim3_B_i,
  "3. Political pluralism and participation (FH)" = mod_dim3_C_p, 
  "3. Political pluralism and participation (FH)" = mod_dim3_C_i)

Table_A6 <- modelsummary::modelsummary(Table_A6_models, 
                                                  coef_map = cm_table,
                                                  # output = "flextable",
                                                  estimate = "{estimate}{stars} ({std.error})",
                                                  conf_level = .9,
                                                  gof_omit = 'R2 Within|R2 Within Adj.|AIC|BIC|RMSE',
                                                  statistic = NULL,
                                                  fmt = 3)

Table_A7_models <- list(
  "4. Party system closure (PSGO)" = mod_dim4_A_p, 
  "4. Party system closure (PSGO)" = mod_dim4_A_i,
  "4. Volatility (DEV)" = mod_dim4_B_p, 
  "4. Volatility (DEV)" = mod_dim4_B_i,
  "4. Party system innovation (DEV)" = mod_dim4_C_p,
  "4. Party system innovation (DEV)" = mod_dim4_C_i)

Table_A7 <- modelsummary::modelsummary(Table_A7_models, 
                                                  coef_map = cm_table,
                                                  # output = "flextable",
                                                  estimate = "{estimate}{stars} ({std.error})",
                                                  conf_level = .9,
                                                  gof_omit = 'R2 Within|R2 Within Adj.|AIC|BIC|RMSE',
                                                  statistic = NULL,
                                                  fmt = 3)

Table_A8_models <- list(
  "5. Freedom from political killings (V-Dem)" = mod_dim5_A_p,
  "5. Freedom from political killings (V-Dem)" = mod_dim5_A_i,
  "5. Freedom from forced labor for women (V-Dem)" = mod_dim5_B_p,
  "5. Freedom from forced labor for women (V-Dem)" = mod_dim5_B_i,
  "5. Freedom of academic discussion (V-Dem)" = mod_dim5_C_p, 
  "5. Freedom of academic discussion (V-Dem)" = mod_dim5_C_i)

Table_A8 <- modelsummary::modelsummary(Table_A8_models, 
                                                  coef_map = cm_table,
                                                  # output = "flextable",
                                                  estimate = "{estimate}{stars} ({std.error})",
                                                  conf_level = .9,
                                                  gof_omit = 'R2 Within|R2 Within Adj.|AIC|BIC|RMSE',
                                                  statistic = NULL,
                                                  fmt = 3)

Table_A9_models <- list(
  "6. Education 15+ (CLIO)" = mod_dim6_A_p, 
  "6. Education 15+ (CLIO)" = mod_dim6_A_i,
  "6. Income gini (LIS)" =  mod_dim6_B_p, 
  "6. Income gini (LIS)" = mod_dim6_B_i,
  "6. Subnational election eveness (V-Dem)" = mod_dim6_C_p, 
  "6. Subnational election eveness (V-Dem)" = mod_dim6_C_i)

Table_A9 <- modelsummary::modelsummary(Table_A9_models, 
                                                  coef_map = cm_table,
                                                  # output = "flextable",
                                                  estimate = "{estimate}{stars} ({std.error})",
                                                  conf_level = .9,
                                                  gof_omit = 'R2 Within|R2 Within Adj.|AIC|BIC|RMSE',
                                                  statistic = NULL,
                                                  fmt = 3)

Table_A10_models <- list(
  "7. Left-right issue congruence (DB)" = mod_dim7_A_i,
  "7. Left-right issue congruence (DB)" = mod_dim7_A_p,
  "7. Party pledge fulfillment (CPP)" = mod_dim7_B_p,
  "7. Party pledge fulfillment (CPP)" = mod_dim7_B_i,
  "7. Satisfaction with democracy (HUMAN)" = mod_dim7_C_p,
  "7. Satisfaction with democracy (HUMAN)" = mod_dim7_C_i)

Table_A10 <- modelsummary::modelsummary(Table_A10_models, 
                                                  coef_map = cm_table,
                                                  # output = "flextable",
                                                  estimate = "{estimate}{stars} ({std.error})",
                                                  conf_level = .9,
                                                  gof_omit = 'R2 Within|R2 Within Adj.|AIC|BIC|RMSE',
                                                  statistic = NULL,
                                                  fmt = 3)
Table_A4
Table_A5
Table_A6
Table_A7
Table_A8
Table_A9
Table_A10

# Appendix models
Table_A11_models <- list(
  "Rule of Law (BTI)" = modapp_dim1_A_p, 
  "Rule of Law (BTI)" = modapp_dim1_A_i,
  "Rule of Law (WJP)" = modapp_dim1_B_p, 
  "Rule of Law (WJP)" = modapp_dim1_B_i,
  "Rule of Law (FH)" = modapp_dim1_C_p, 
  "Rule of Law (FH)" = modapp_dim1_C_i,
  "Transparency (DB)" = modapp_dim1_D_p, 
  "Transparency (DB)" = modapp_dim1_D_i,
  "Confidence in the police (DB)" = modapp_dim1_E_p, 
  "Confidence in the police (DB)" = modapp_dim1_E_i)

Table_A11 <- modelsummary::modelsummary(Table_A11_models, 
                                              coef_map = cm_table,
                                              # output = "flextable",
                                              estimate = "{estimate}{stars} ({std.error})",
                                              conf_level = .9,
                                              gof_omit = 'R2 Within|R2 Within Adj.|AIC|BIC|RMSE',
                                              statistic = NULL,
                                              fmt = 3)

Table_A12_models <- list(
  "Executive accountability (BTI)" = modapp_dim2_A_p, 
  "Executive accountability (BTI)" = modapp_dim2_A_i,
  "Independent Supervisory Bodies (BTI)" = modapp_dim2_B_p, 
  "Independent Supervisory Bodies (BTI)" = modapp_dim2_B_i,
  "Electoral reforms (IDEA)" = modapp_dim2_C_p, 
  "Electoral reforms (IDEA)" = modapp_dim2_C_i,
  "Diagonal accountability (V-Dem)" = modapp_dim2_D_p,
  "Diagonal accountability (V-Dem)" = modapp_dim2_D_i)

Table_A12 <- modelsummary::modelsummary(Table_A12_models, 
                                              coef_map = cm_table,
                                              # output = "flextable",
                                              estimate = "{estimate}{stars} ({std.error})",
                                              conf_level = .9,
                                              gof_omit = 'R2 Within|R2 Within Adj.|AIC|BIC|RMSE',
                                              statistic = NULL,
                                              fmt = 3)

Table_A13_models <- list(
  "Mass mobilization (V-Dem)" = modapp_dim3_A_p , 
  "Mass mobilization (V-Dem)" = modapp_dim3_A_i,
  "Participation index (Vanhanen)" = modapp_dim3_B_p, 
  "Participation index (Vanhanen)" = modapp_dim3_B_i,
  "Turnout (IDEA)" = modapp_dim3_C_p,
  "Turnout (IDEA)" = modapp_dim3_C_i,
  "Turnout EP elections (IDEA)" = modapp_dim3_D_p,
  "Turnout EP elections (IDEA)" = modapp_dim3_D_i)

Table_A13 <- modelsummary::modelsummary(Table_A13_models, 
                                              coef_map = cm_table,
                                              # output = "flextable",
                                              estimate = "{estimate}{stars} ({std.error})",
                                              conf_level = .9,
                                              gof_omit = 'R2 Within|R2 Within Adj.|AIC|BIC|RMSE',
                                              statistic = NULL,
                                              fmt = 3)

Table_A14_models <- list(
  "Competition (DB)" = modapp_dim4_A_p,
  "Competition (DB)" = modapp_dim4_A_i,
  "Competition index (Vanhanen)" = modapp_dim4_B_p, 
  "Competition index (Vanhanen)" = modapp_dim4_B_i,
  "Electoral Fragmentation (PSGO)" = modapp_dim4_C_p,
  "Electoral Fragmentation (PSGO)" = modapp_dim4_C_i,
  "Legislative fract. party system (Rae/CPD)" = modapp_dim4_D_p,
  "Legislative fract. party system (Rae/CPD)" = modapp_dim4_D_i,
  "Total volatility EP (DEV)" = modapp_dim4_E_p, 
  "Total volatility EP (DEV)" = modapp_dim4_E_i)

Table_A14 <- modelsummary::modelsummary(Table_A14_models, 
                                              coef_map = cm_table,
                                              # output = "flextable",
                                              estimate = "{estimate}{stars} ({std.error})",
                                              conf_level = .9,
                                              gof_omit = 'R2 Within|R2 Within Adj.|AIC|BIC|RMSE',
                                              statistic = NULL,
                                              fmt = 3)

Table_A15_models <- list(
  "Freedom from torture (V-Dem)" = modapp_dim5_A_p,
  "Freedom from torture (V-Dem)" = modapp_dim5_A_i,
  "State ownership of economy (V-Dem)" = modapp_dim5_B_p,
  "State ownership of economy (V-Dem)" = modapp_dim5_B_i,
  "Freedom of the Press (FoP)" = modapp_dim5_C_p,
  "Freedom of the Press (FoP)" = modapp_dim5_C_i,
  "Freedom of expression and belief (FH)" = modapp_dim5_D_p,
  "Freedom of expression and belief (FH)" = modapp_dim5_D_i,
  "Civil Rights and Political liberties (BTI)" = modapp_dim5_E_p,
  "Civil Rights and Political liberties (BTI)" = modapp_dim5_E_i)

Table_A15 <- modelsummary::modelsummary(Table_A15_models, 
                                              coef_map = cm_table,
                                              # output = "flextable",
                                              estimate = "{estimate}{stars} ({std.error})",
                                              conf_level = .9,
                                              gof_omit = 'R2 Within|R2 Within Adj.|AIC|BIC|RMSE',
                                              statistic = NULL,
                                              fmt = 3)

Table_A16_models <- list(
  "Health inequality (V-Dem)" = modapp_dim6_A_p,
  "Health inequality (V-Dem)" = modapp_dim6_A_i,
  "Gender inequality index (UN)" = modapp_dim6_B_p,
  "Gender inequality index (UN)" = modapp_dim6_B_i,
  "Income gini (CSP)" = modapp_dim6_C_p,
  "Income gini (CSP)" = modapp_dim6_C_i,
  "Social inclusion (BTI)" = modapp_dim6_D_p,
  "Social inclusion (BTI)" = modapp_dim6_D_i,
  "Health (BTI)" = modapp_dim6_E_p,
  "Health (BTI)" = modapp_dim6_E_i)

Table_A16 <- modelsummary::modelsummary(Table_A16_models, 
                                              coef_map = cm_table,
                                              # output = "flextable",
                                              estimate = "{estimate}{stars} ({std.error})",
                                              conf_level = .9,
                                              gof_omit = 'R2 Within|R2 Within Adj.|AIC|BIC|RMSE',
                                              statistic = NULL,
                                              fmt = 3)

Table_A17_models <- list(
  "Confidence in government (DB)" = modapp_dim7_A_p,
  "Confidence in government (DB)" = modapp_dim7_A_i)

Table_A17 <- modelsummary::modelsummary(Table_A17_models, 
                                              coef_map = cm_table,
                                              # output = "flextable",
                                              estimate = "{estimate}{stars} ({std.error})",
                                              conf_level = .9,
                                              gof_omit = 'R2 Within|R2 Within Adj.|AIC|BIC|RMSE',
                                              statistic = NULL,
                                              fmt = 3)

Table_A11
Table_A12
Table_A13
Table_A14
Table_A15
Table_A16
Table_A17
